home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 September / Software of the Month Club 1996 September.iso / mac / Software Research Institute-SRI / Business / Alpha ƒ / Tcl / SystemCode / latexMacros.tcl < prev    next >
Encoding:
Text File  |  1995-12-21  |  88.6 KB  |  3,074 lines  |  [TEXT/ALFA]

  1. #############################################################################
  2. #############################################################################
  3. #
  4. # latexMacros.tcl (called from latex.tcl)
  5. #
  6. #############################################################################
  7. #
  8. # Author:  Tom Scavo <trscavo@syr.edu>
  9. #
  10. #############################################################################
  11. #############################################################################
  12.  
  13. #############################################################################
  14. # Basic Commands
  15. #
  16. #############################################################################
  17.  
  18. proc typesetWindow {} {
  19.     global PREFS
  20.     
  21.     # Initialization:
  22.     foreach flag {isOzTeX isTextures isCMacTeX isDirectTeX isDirectTeXPro} {
  23.         set $flag 0
  24.     }
  25.     set currentWin [lindex [winNames -f] 0]
  26.     set currentDir [file dirname $currentWin]
  27.     set currentDoc [file tail $currentWin]
  28.     set docBasename [file rootname $currentDoc]
  29.     set docExtension [file extension $currentDoc]
  30.     
  31.     # Is the window untitled or dirty?
  32.     if {[string match $currentWin $currentDoc]} {
  33.         case [askyesno -c "Save \"$currentDoc\"?"] in {
  34.             "yes" {
  35.                 if {[catch {set currentWin [saveAs "Untitled\.tex"]}]} then {return}
  36.             }
  37.             "no" {
  38.                 if {[regexp {<(.*)>} $currentDoc dummy num]} {
  39.                     set tmpFilename "Untitled$num\.tex"
  40.                 } else {
  41.                     set tmpFilename "Untitled\.tex"
  42.                 }
  43.                 set text [getText 0 [maxPos]]
  44.                 set newDoc "$PREFS:$tmpFilename"
  45.                 message "Saving $newDoc..."
  46.                 set fd [open $newDoc "w"]
  47.                 puts $fd $text
  48.                 close $fd
  49.                 set currentWin $newDoc
  50.             }
  51.             "cancel" {return}
  52.         }
  53.     } elseif {[winDirty]} {
  54.         case [askyesno -c "Save \"$currentDoc\"?"] in {
  55.             "yes" {save}
  56.             "no" {
  57.                 set text [getText 0 [maxPos]]
  58.                 set newDoc "$PREFS:temp-$currentDoc"
  59.                 message "Saving $newDoc..."
  60.                 set fd [open $newDoc "w"]
  61.                 puts $fd $text
  62.                 close $fd
  63.                 set currentWin $newDoc
  64.             }
  65.             "cancel" {return}
  66.         }
  67.     }
  68.     typeset $currentWin
  69. }
  70.  
  71. # proc typesetSelection {} {
  72. #     global PREFS
  73. #     if { [isSelection] } then { 
  74. #         set pos1 [getPos]
  75. #         if { [isInDocument] } then {
  76. #             exchangePointAndMark
  77. #             set pos2 [getPos]
  78. #             if { [isInDocument] } then {
  79. #                 set body "\r[getText $pos1 $pos2]\r"
  80. #                 set pattern {(\\documentclass.*)\\begin\{document\}}
  81. #                 set searchText [getText 0 [maxPos]]
  82. #                 if {![regexp $pattern $searchText dummy preamble]} then {return}
  83. #                 append text $preamble [buildEnvironment "document" "" $body "\r"]
  84. #                 select $pos1 $pos2
  85. #                 set newDoc "$PREFS:temp-noname\.tex"
  86. #                 message "Saving $newDoc..."
  87. #                 set fd [open $newDoc "w"]
  88. #                 puts $fd $text
  89. #                 close $fd
  90. #                 set currentWin $newDoc
  91. #                 typeset $currentWin
  92. #             } else {
  93. #                 beep
  94. #                 message "selection not in document environment"
  95. #             }
  96. #         } else {
  97. #             beep
  98. #             message "selection not in document environment"
  99. #         }
  100. #     } else {
  101. #         beep
  102. #         message "no selection"
  103. #     }
  104. # }
  105.  
  106. proc typesetSelection {} {
  107.     global PREFS
  108.     if { [isSelection] } then { 
  109.         set pos1 [getPos]
  110.         if { [isInDocument] } then {
  111.             exchangePointAndMark
  112.             set pos2 [getPos]
  113.             if { [isInDocument] } then {
  114.                 # fall through
  115.             } else {
  116.                 beep
  117.                 set msg "Selection not in document environment.  Continue?"
  118.                 if { [askyesno $msg] == "no" } then { return }
  119.             }
  120.         } else {
  121.             beep
  122.             set msg "Selection not in document environment.  Continue?"
  123.             if { [askyesno $msg] == "no" } then { return }
  124.             set pos2 [selEnd]
  125.         }
  126.         set body "\r[getText $pos1 $pos2]\r"
  127.         set pattern {(\\documentclass.*)\\begin\{document\}}
  128.         set searchText [getText 0 [maxPos]]
  129.         if {![regexp $pattern $searchText dummy preamble]} then {
  130.             set preamble "\\documentclass\{article\}\r"
  131.         }
  132.         append text $preamble [buildEnvironment "document" "" $body "\r"]
  133.         select $pos1 $pos2
  134.         set newDoc "$PREFS:temp-noname\.tex"
  135.         message "Saving $newDoc..."
  136.         set fd [open $newDoc "w"]
  137.         puts $fd $text
  138.         close $fd
  139.         set currentWin $newDoc
  140.         typeset $currentWin
  141.     } else {
  142.         beep
  143.         message "no selection"
  144.     }
  145. }
  146.  
  147. proc typeset {filename} {
  148.     global texPath TeXmodeVars
  149.     
  150.     # Check if a TeX app is running.  If not, open the app named in 
  151.     # $texPath (if defined) or have the user select an app via a
  152.     # standard file dialog.  Leave the TeX app in the background.
  153.     set appName [checkRunning TeX {OTEX *TEX *XeT MPS* TeX+} texPath 0]
  154.     
  155.     if {[string match {OzTeX*} $appName]} {
  156.         set isOzTeX 1
  157.     } elseif {[string match {Euro-OzTeX*} $appName]} {
  158.         set isOzTeX 1
  159.     } elseif {[string match {Textures*} $appName]} {
  160.         set isTextures 1
  161.     } elseif {[string match {DirectTeX*} $appName]} {
  162.         set isDirectTeXPro 1
  163.     } elseif {[string match {*tex} $appName]} {
  164.         set isCMacTeX 1
  165.     } elseif {[string match {MPW*} $appName]} {
  166.         set isDirectTeX 1
  167.     } else {
  168.         alertnote "Sorry, I don't know how to talk to \"$appName\"."
  169.         return
  170.     }
  171.     
  172.     # Conditionally bring the TeX app to the foreground:
  173.     if {$TeXmodeVars(runTeXInBackground) == 0} { switchTo $appName }
  174.     
  175.     # Typeset the document:
  176.     if {$isOzTeX} {
  177.         sendOpenEvent -n $appName $filename
  178.     } elseif {$isTextures} {
  179.         # Choose one of the following three options:
  180.         # dosc -c '*TEX' -s [getText 0 [maxPos]] -r
  181.         # sendOpenEvent -n $appName $filename
  182.         dosc -c '*TEX' -f [lindex [winNames -f] 0] -r
  183.     } elseif {$isDirectTeXPro} {
  184.         dosc -c 'TeX+' -s "ProjectMgr -t LaTeX \"$filename\"; SelectApp; MenuCommand 1 4"
  185.     } elseif {$isCMacTeX} {
  186.         dosc -n $appName -k 'aevt' -e 'odoc' -r -f $filename
  187.     } elseif {$isDirectTeX} {
  188.         set script "Begin; ChangeTeXProject '$filename' -check -confirm || Exit 0;\
  189.                       Execute \"{dt_TeXProject}\"; TeXMenu -tex -formats; End ╖ Dev:Null;\
  190.                       RunSession 1 ╖ Dev:Null"
  191.         dosc -r -n $appName -s $script
  192.     }
  193. }
  194.  
  195.  
  196. #--------------------------------------------------------------------------
  197. # Goto:
  198. #--------------------------------------------------------------------------
  199.  
  200. # Switch to (but don't execute) any of the following applications.
  201. proc latex {} {
  202.     global texPath
  203.     if {![catch {getFileSig $texPath} sig]} {
  204.         set appName [checkRunning TeX $sig texPath]
  205.     } else {
  206.         set appName [checkRunning TeX {OTEX *TEX *XeT MPS* TeX+} texPath]
  207.     }
  208.     if {[string length $appName] > 0} {
  209.         switchTo $appName
  210.     }
  211. }
  212. proc bibtex {} {
  213.     global bibtexPath
  214.     set appName [checkRunning BibTeX BIBt bibtexPath]
  215.     if {![string length $appName]} return
  216.     switchTo $appName
  217. }
  218. proc makeindex {} {
  219.     global makeindexPath
  220.     set appName [checkRunning MakeIndex Midx makeindexPath]
  221.     if {![string length $appName]} return
  222.     switchTo $appName
  223. }
  224.  
  225. # Find the next or previous environment.  Search forward (or backward, 
  226. # depending on $forward) for either \begin or \end.  If \begin is found, 
  227. # search forward for corresponding \end; otherwise, search backward for 
  228. # corresponding \begin.  Select the found environment, or display an 
  229. # error message if no environment is found.
  230. proc findEnvironment {forward} {
  231.     set searchString1 {^[ \t]*\\begin\{[^\{\}]*\}|\\end\{[^\{\}]*\}[ \t]*\r?}
  232.     set searchPos [getPos]
  233.     if { [isSelection] } then { 
  234.         if { $forward } then {
  235.             set searchPos [selEnd]
  236.         } else {
  237.             set searchPos [expr $searchPos - 1]
  238.         }
  239.     } else {
  240.         if { $forward } then {
  241.             set searchPos [expr $searchPos + 1]
  242.         } else {
  243.             set searchPos [expr $searchPos - 1]
  244.         }
  245.     }
  246.     set searchResult [search -s -f $forward -r 1 -n $searchString1 $searchPos]
  247.     if {[string length $searchResult]} then {
  248.         set begPos [lindex $searchResult 0]
  249.         set endPos [lindex $searchResult 1]
  250.         set searchText [getText $begPos $endPos]
  251.         regexp {\{(.*)\}} $searchText dummy envName
  252.         if {[string match {*begin*} $searchText]} {
  253.             set begEnv $begPos
  254.             append searchString2 {\\end\{} $envName {\}[ \t]*\r?}
  255.             set searchPos $endPos
  256.             set searchResult [search -s -f 1 -r 1 -n $searchString2 $searchPos]
  257.             if {[string length $searchResult]} {
  258.                 set endPos [lindex $searchResult 1]
  259.                 return [list $begPos $endPos]
  260.             } else {
  261.                 return "matching \\end not found"
  262.             }
  263.         } else {
  264.             set endEnv $endPos
  265.             append searchString2 {^[ \t]*\\begin\{} $envName {\}}
  266.             set searchPos $begPos
  267.             set searchResult [search -s -f 0 -r 1 -n $searchString2 $searchPos]
  268.             if {[string length $searchResult]} {
  269.                 set begPos [lindex $searchResult 0]
  270.                 return [list $begPos $endPos]
  271.             } else {
  272.                 return "matching \\begin not found"
  273.             }
  274.         }
  275.     } else {
  276.         if { $forward } then {
  277.             return "next environment not found"
  278.         } else {
  279.             return "previous environment not found"
  280.         }
  281.     }
  282. }
  283.  
  284. proc prevEnvironment {} {
  285.     global searchNoisily
  286.     set findResult [findEnvironment 0]
  287.     if {[llength $findResult] == 2} then {
  288.         goto [lindex $findResult 0]
  289.     } else {
  290.         if {$searchNoisily} {beep}
  291.         message $findResult
  292.     }
  293. }
  294. proc nextEnvironment {} {
  295.     global searchNoisily
  296.     set findResult [findEnvironment 1]
  297.     if {[llength $findResult] == 2} then {
  298.         goto [lindex $findResult 0]
  299.     } else {
  300.         if {$searchNoisily} {beep}
  301.         message $findResult
  302.     }
  303. }
  304. proc prevEnvironmentSelect {} {
  305.     global searchNoisily
  306.     set forward 0
  307.     set findResult [findEnvironment $forward]
  308.     if {[llength $findResult] == 2} then {
  309.         set endPos [lindex $findResult 1]
  310. #         if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
  311. #             set endPos [expr $endPos + 1]
  312. #         }
  313.         select [lindex $findResult 0] $endPos
  314.     } else {
  315.         if { $searchNoisily } {beep}
  316.         message $findResult
  317.     }
  318. }
  319. proc nextEnvironmentSelect {} {
  320.     global searchNoisily
  321.     set forward 1
  322.     set findResult [findEnvironment $forward]
  323.     if {[llength $findResult] == 2} then {
  324.         set endPos [lindex $findResult 1]
  325. #         if { [regexp {\r} [lookAt [expr $endPos + 1]]] } then {
  326. #             set endPos [expr $endPos + 1]
  327. #         }
  328.         select [lindex $findResult 0] $endPos
  329.     } else {
  330.         if { $searchNoisily } {beep}
  331.         message $findResult
  332.     }
  333. }
  334.  
  335. # Find a LaTeX command in either direction.  It's up to the calling
  336. # procedure to pass the correct starting position of the search.
  337. proc findCommand {pos direction} {
  338. #    Handle "\ " and "\[" separately:
  339.     set searchString {(\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?)|([^\\]\\\ )|([^\\]\\\[)}
  340.     set searchResult [search -s -f $direction -r 1 -n $searchString $pos]
  341.     if { [string length $searchResult] } {
  342.         set begPos [lindex $searchResult 0]
  343.         set endPos [lindex $searchResult 1]
  344.         set lastChar [lookAt [expr $endPos - 1]]
  345.         if {$lastChar == "\ " || $lastChar == "\["} then {
  346.             return [list [expr $begPos + 1] $endPos]
  347.         } else {}
  348.     }
  349.     return $searchResult
  350. # Handles everything but "\ " and "\[":
  351. #     set searchString {\\([^a-zA-Z\t\r* []|[a-zA-Z]+)\*?}
  352. #     return [search -s -f $direction -r 1 -n $searchString $pos]
  353. }
  354. # Find and goto the beginning of the previous LaTeX command.
  355. proc prevCommand {} {
  356.     global searchNoisily
  357.     set pos [getPos]
  358.     if {$pos > 0} then {
  359.         set searchResult [findCommand [expr $pos - 1] 0]
  360.         if { [string length $searchResult] } {
  361.             goto [lindex $searchResult 0]
  362.             return
  363.         } else {}
  364.     }
  365.     if { $searchNoisily } {beep}
  366.     message "previous command not found"
  367. }
  368. # Find and goto the beginning of the next LaTeX command.
  369. proc nextCommand {} {
  370.     global searchNoisily
  371.     set pos [getPos]
  372.     if {$pos < [maxPos]} then {
  373.         set searchResult [findCommand [expr $pos + 1] 1]
  374.         if { [string length $searchResult] } {
  375.             goto [lindex $searchResult 0]
  376.             return
  377.         } else {}
  378.     }
  379.     if { $searchNoisily } {beep}
  380.     message "next command not found"
  381. }
  382. # Select the previous LaTeX command, but do not attempt to select
  383. # any associated argument.
  384. proc prevCommandSelect {} {
  385.     global searchNoisily
  386.     set pos [getPos]
  387.     if {$pos > 0} then {
  388.         set searchResult [findCommand [expr $pos - 1] 0]
  389.         if { [string length $searchResult] } {
  390.             eval select $searchResult
  391.             return
  392.         } else {}
  393.     }
  394.     if { $searchNoisily } {beep}
  395.     message "previous command not found"
  396. }
  397. # Select the next LaTeX command, but do not attempt to select
  398. # any associated argument.
  399. proc nextCommandSelect {} {
  400.     global searchNoisily
  401.     set pos [getPos]
  402.     if {$pos < [maxPos]} then {
  403.         if { [isSelection] } then {
  404.             set pos [expr $pos + 1]
  405.         }
  406.         set searchResult [findCommand $pos 1]
  407.         if { [string length $searchResult] } {
  408.             eval select $searchResult
  409.             return
  410.         } else {}
  411.     }
  412.     if { $searchNoisily } {beep}
  413.     message "next command not found"
  414. }
  415.  
  416. # Find a LaTeX command with arguments in either direction.  It's up 
  417. # to the calling procedure to pass the starting position of the search.
  418. # (Handles everything but "\ " and commands whose arguments contain
  419. # embedded braces.)
  420. proc findCommandWithArgs {pos direction} {
  421.     set searchString {\\([^a-zA-Z\t\r]|[a-zA-Z]+\*?)(\[.*\])*({[^{}]*})*}
  422.     return [search -s -f $direction -r 1 -n $searchString $pos]
  423. }
  424. # Select the previous LaTeX command and any associated arguments.
  425. proc prevCommandSelectWithArgs {} {
  426.     global searchNoisily
  427.     set pos [getPos]
  428.     if {$pos > 0} then {
  429.         set searchResult [findCommandWithArgs [expr $pos - 1] 0]
  430.         if { [string length $searchResult] } {
  431.             eval select $searchResult
  432.             return
  433.         } else {}
  434.     }
  435.     if { $searchNoisily } {beep}
  436.     message "previous command not found"
  437. }
  438. # Select the next LaTeX command and any associated arguments.
  439. proc nextCommandSelectWithArgs {} {
  440.     global searchNoisily
  441.     set pos [getPos]
  442.     if {$pos < [maxPos]} then {
  443.         if { [isSelection] } then {
  444.             set pos [expr $pos + 1]
  445.         }
  446.         set searchResult [findCommandWithArgs $pos 1]
  447.         if { [string length $searchResult] } {
  448.             eval select $searchResult
  449.             return
  450.         } else {}
  451.     }
  452.     if { $searchNoisily } {beep}
  453.     message "next command not found"
  454. }
  455.  
  456. # Find a LaTeX sectioning command in either direction.  It's up to 
  457. # the calling procedure to pass the starting position of the search.
  458. proc findSection {pos direction} {
  459.     global funcExprAlt
  460.     return [search -s -f $direction -r 1 -n $funcExprAlt $pos]
  461. }
  462. # Select the previous LaTeX sectioning command.
  463. proc prevSection {} {
  464.     global searchNoisily
  465.     set pos [getPos]
  466.     if {$pos > 0} then {
  467.         set searchResult [findSection [expr $pos - 1] 0]
  468.         if { [string length $searchResult] } {
  469.             eval select $searchResult
  470.             return
  471.         } else {}
  472.     }
  473.     if { $searchNoisily } {beep}
  474.     message {previous section not found}
  475. }
  476. # Select the next LaTeX sectioning command.
  477. proc nextSection {} {
  478.     global searchNoisily
  479.     set pos [getPos]
  480.     if {$pos < [maxPos]} then {
  481.         if { [isSelection] } then {
  482.             set pos [expr $pos + 1]
  483.         }
  484.         set searchResult [findSection $pos 1]
  485.         if { [string length $searchResult] } {
  486.             eval select $searchResult
  487.             return
  488.         } else {}
  489.     }
  490.     if { $searchNoisily } {beep}
  491.     message {next section not found}
  492. }
  493. proc prevSectionSelect {} {
  494.     global searchNoisily
  495.     set pos [getPos]
  496.     if {$pos > 0} then {
  497.         set searchResult [findSection [expr $pos - 1] 0]
  498.         if { [string length $searchResult] } {
  499.             set begPos [lindex $searchResult 0]
  500.             set searchPos [expr [lindex $searchResult 1] + 1]
  501.             set searchResult [findSection $searchPos 1]
  502.             if { [string length $searchResult] } {
  503.                 set endPos [lindex $searchResult 0]
  504.             } else {
  505.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  506.                 set endPos [lindex $searchResult 0]
  507.             }
  508.             select $begPos $endPos
  509.             return
  510.         } else {}
  511.     }
  512.     if { $searchNoisily } {beep}
  513.     message {previous section not found}
  514. }
  515. # Select the next LaTeX sectioning command.
  516. proc nextSectionSelect {} {
  517.     global searchNoisily
  518.     set pos [getPos]
  519.     if {$pos < [maxPos]} then {
  520.         if { [isSelection] } then {
  521.             set pos [expr $pos + 1]
  522.         }
  523.         set searchResult [findSection $pos 1]
  524.         if { [string length $searchResult] } {
  525.             set begPos [lindex $searchResult 0]
  526.             set searchPos [expr [lindex $searchResult 1] + 1]
  527.             set searchResult [findSection $searchPos 1]
  528.             if { [string length $searchResult] } {
  529.                 set endPos [lindex $searchResult 0]
  530.             } else {
  531.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  532.                 set endPos [lindex $searchResult 0]
  533.             }
  534.             select $begPos $endPos
  535.             return
  536.         } else {}
  537.     }
  538.     if { $searchNoisily } {beep}
  539.     message {next section not found}
  540. }
  541.  
  542. # Find a LaTeX subsectioning command in either direction.  It's up to 
  543. # the calling procedure to pass the starting position of the search.
  544. proc findSubsection {pos direction} {
  545.     global funcExpr
  546.     return [search -s -f $direction -r 1 -n $funcExpr $pos]
  547. }
  548. proc prevSubsection {} {
  549.     global searchNoisily
  550.     set pos [getPos]
  551.     if {$pos > 0} then {
  552.         set searchResult [findSubsection [expr $pos - 1] 0]
  553.         if { [string length $searchResult] } {
  554.             eval select $searchResult
  555.             return
  556.         } else {}
  557.     }
  558.     if { $searchNoisily } {beep}
  559.     message {previous (sub)*section not found}
  560. }
  561. # Select the next LaTeX sectioning command.
  562. proc nextSubsection {} {
  563.     global searchNoisily
  564.     set pos [getPos]
  565.     if {$pos < [maxPos]} then {
  566.         if { [isSelection] } then {
  567.             set pos [expr $pos + 1]
  568.         }
  569.         set searchResult [findSubsection $pos 1]
  570.         if { [string length $searchResult] } {
  571.             eval select $searchResult
  572.             return
  573.         } else {}
  574.     }
  575.     if { $searchNoisily } {beep}
  576.     message {next (sub)*section not found}
  577. }
  578. proc prevSubsectionSelect {} {
  579.     global searchNoisily
  580.     set pos [getPos]
  581.     if {$pos > 0} then {
  582.         set searchResult [findSubsection [expr $pos - 1] 0]
  583.         if { [string length $searchResult] } {
  584.             set begPos [lindex $searchResult 0]
  585.             set endPos [lindex $searchResult 1]
  586.             set searchPos [expr $endPos + 1]
  587.             set commandName [extractCommandName [getText $begPos $endPos]]
  588.             if {[string match {section*} $commandName]} then {
  589.                 set searchResult [findSection $searchPos 1]
  590.             } else {
  591.                 set searchResult [findSubsection $searchPos 1]
  592.             }
  593.             if { [string length $searchResult] } {
  594.                 set endPos [lindex $searchResult 0]
  595.             } else {
  596.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  597.                 set endPos [lindex $searchResult 0]
  598.             }
  599.             select $begPos $endPos
  600.             return
  601.         } else {}
  602.     }
  603.     if { $searchNoisily } {beep}
  604.     message {previous (sub)*section not found}
  605. }
  606. # Select the next LaTeX sectioning command.
  607. proc nextSubsectionSelect {} {
  608.     global searchNoisily
  609.     set pos [getPos]
  610.     if {$pos < [maxPos]} then {
  611.         if { [isSelection] } then {
  612.             set pos [expr $pos + 1]
  613.         }
  614.         set searchResult [findSubsection $pos 1]
  615.         if { [string length $searchResult] } {
  616.             set begPos [lindex $searchResult 0]
  617.             set endPos [lindex $searchResult 1]
  618.             set searchPos [expr $endPos + 1]
  619.             set commandName [extractCommandName [getText $begPos $endPos]]
  620.             if {[string match {section*} $commandName]} then {
  621.                 set searchResult [findSection $searchPos 1]
  622.             } else {
  623.                 set searchResult [findSubsection $searchPos 1]
  624.             }
  625.             if { [string length $searchResult] } {
  626.                 set endPos [lindex $searchResult 0]
  627.             } else {
  628.                 set searchResult [search -s -f 1 -r 0 -n "\\end{document}" $searchPos]
  629.                 set endPos [lindex $searchResult 0]
  630.             }
  631.             select $begPos $endPos
  632.             return
  633.         } else {}
  634.     }
  635.     if { $searchNoisily } {beep}
  636.     message {next (sub)*section not found}
  637. }
  638.  
  639. proc gotoTabStop {dirIndicator} {
  640.     set pos [getPos]
  641.     if {$dirIndicator} then {
  642.         if {$pos == [maxPos]} {return 0}
  643.     } else {
  644.         if {$pos == 0} {
  645.             set pos [expr $pos - 1]
  646.             return 0
  647.         }
  648.     }
  649.     set searchResult [search -s -n -f $dirIndicator -m 0 -i 1 -r 0 {Ñ} $pos]
  650.     if {[string length $searchResult]} then {
  651.         goto [lindex $searchResult 0]
  652.         return 1
  653.     } else {
  654.         return 0
  655.     }
  656. }
  657. proc nextTabStop {} {
  658.     global searchNoisily
  659.     set forward 1
  660.     if {[gotoTabStop $forward]} then {
  661.         deleteChar
  662.     } else {
  663.         if {$searchNoisily} {beep}
  664.         message "tab stop not found"
  665.     }
  666. }
  667. proc prevTabStop {} {
  668.     global searchNoisily
  669.     set forward 0
  670.     if {[gotoTabStop $forward]} then {
  671.         deleteChar
  672.     } else {
  673.         if {$searchNoisily} {beep}
  674.         message "tab stop not found"
  675.     }
  676. }
  677. # Goto the nth tab stop.  A nonzero argument is non-interactive
  678. # (for use in Tcl procs) and not validated.
  679. proc nthTabStop {{numTabStops 0}} {
  680.     global searchNoisily promptNoisily useStatusBar
  681.     if {$numTabStops == 0} then {
  682.         if {$promptNoisily && $useStatusBar} {beep}
  683.         catch {sPrompt "How many tab stops?" "3"} numTabStops
  684.         if {$numTabStops == "cancel" || $numTabStops == 0} then {
  685.             return
  686.         } elseif {![isInteger $numTabStops]} then {
  687.             beep
  688.             message "invalid input:  integer required"
  689.             return
  690.         }
  691.     }
  692.     set currentPos [getPos]
  693.     if {$numTabStops > 0} {set forward 1} {set forward 0}
  694.     set maxits [expr abs($numTabStops)]
  695.     if {![gotoTabStop $forward]} then {
  696.         if {$searchNoisily} {beep}
  697.         message "tab stop not found"
  698.         goto $currentPos
  699.         return
  700.     }
  701.     for {set i 1} {$i < $maxits} {incr i} {
  702.         if {$forward} {forwardChar} {backwardChar}
  703.         if {![gotoTabStop $forward]} then {
  704.             if {$searchNoisily} {beep}
  705.             message "tab stop not found"
  706.             goto $currentPos
  707.             return
  708.         }
  709.     }
  710.     deleteChar
  711. }
  712.  
  713. #--------------------------------------------------------------------------
  714. # Utilities:
  715. #--------------------------------------------------------------------------
  716.  
  717. # A keyboard-bound method of accessing menu commands.  Assumes the 
  718. # existence of two procs: 1) a proc called 'get___Menu', which 
  719. # returns the menu to be processed; and 2) a proc called '___MenuItem',
  720. # which filters menu items.  For example, in latex.tcl there are procs
  721. # called 'getLaTeXMenu' and 'LaTeXMenuItem' (see latexMenu.tcl).  To 
  722. # choose a command from the LaTeX menu, execute 'chooseCommand LaTeX' 
  723. # from the Tcl shell, or from within a proc.
  724.  
  725. proc chooseCommand {mode {men {}} {level 1}} {
  726.     watchCursor
  727.     # If the first time through, get the menu:
  728.     if {![string length $men]} {
  729.         if {$level == 1} {
  730.             set men    [get${mode}Menu]
  731.         } else {
  732.             error "empty submenu"
  733.         }
  734.     }
  735.     # Process the menu:
  736.     foreach    item $men {
  737.         regsub -all {[<!/].} $item {} item
  738.         regsub -all {╔}    $item {} item
  739.         lappend    menOut $item
  740.         if {[string match "menu*" $item]} {
  741.             if {[set ind [lsearch $item {-n}]] >= 0} {
  742.                 lappend    top "[lindex $item [incr    ind]]:"
  743.             }
  744.         } elseif {![string match "(*" $item]} {
  745.             lappend    top $item
  746.         }
  747.     }
  748.     # Present the menu items to the user:
  749.     set res    [listpick -p "$mode menu (level $level):" $top]
  750.     # Either execute a command or recurse on a submenu:
  751.     if {[lsearch $menOut $res] >= 0} {
  752.         ${mode}MenuItem dummy    $res
  753.     } else {
  754.         set res [string trimright $res {:}]
  755.         foreach    item $menOut {
  756.             if {[set ind [lsearch $item $res]] >= 0} {
  757.                 return [chooseCommand $mode [lindex $item end] [incr level]]
  758.             }
  759.         }
  760.     }
  761. }
  762.  
  763. proc insertLiteralTab {} {
  764.     if {[isSelection]} then {
  765.         deleteSelection
  766.     }
  767.     insertText "\t"
  768. }
  769.  
  770. proc insertTabStop {} {
  771.     if {[isSelection]} then {
  772.         deleteSelection
  773.     }
  774.     insertText "Ñ"
  775. }
  776.  
  777. proc insertReference {} {
  778.     set end [maxPos]
  779.     set pos 0
  780.     set labels {}
  781.     
  782.     set exp {\\label\{(.*)\}}
  783.     while {![catch {search -s -f 1 -r 1 -m 0 -i 0 $exp $pos} res]} {
  784.         set start [lindex $res 0]
  785.         set end [lindex $res 1]
  786.         set text [getText $start $end]
  787.         regexp {\{(.*)\}} $text dummy label
  788.         lappend labels $label
  789.         set pos [expr $end +1]
  790.     }
  791.  
  792.     set ref [listpick -p "Select a reference to insert" [lsort $labels]]
  793.     if {[string length $ref]} {
  794.         insertText "\\ref\{$ref\}"
  795.     }    
  796. }
  797.  
  798. # Removes all tab stops from the current selection (if there is one) 
  799. # or the current document, maintaining the cursor position in the 
  800. # latter case.
  801. proc deleteTabStops {} {
  802.     global searchNoisily
  803.     watchCursor
  804.     set subs1 0; set subs2 0; set subs3 0
  805.     set pos [getPos]
  806.     if {[set start $pos] == [set end [selEnd]]} {
  807.         set messageString "document"
  808.         set start 0
  809.         set end [maxPos]
  810.         set text1 [getText $start $pos]
  811.         set subs1 [regsub -all {Ñ} $text1 {} text1]
  812.         set text2 [getText $pos $end]
  813.         set subs2 [regsub -all {Ñ} $text2 {} text2]
  814.         append text $text1 $text2
  815.     } else {
  816.         set messageString "selection"
  817.         set text [getText $start $end]
  818.         set subs3 [regsub -all {Ñ} $text {} text]
  819.     }
  820.     if {$subs1 || $subs2 || $subs3} then {
  821.         replaceText $start $end $text
  822.         if {$messageString == "document"} then {
  823.             goto [expr $pos - $subs1]
  824.         } else {
  825.             set end [getPos]
  826.             select $start $end
  827.         }
  828.         set subs [expr $subs1 + $subs2 + $subs3]
  829.         message "$subs tab stops removed from $messageString"
  830.     } else {
  831.         if {$searchNoisily} {beep}
  832.         message "no tab stops found in $messageString"
  833.     }
  834. }
  835.  
  836. # Delete all unnecessary comments from the current document:
  837. proc deleteComments {} {
  838.     case [askyesno "Warning!  This operation can not be undone.  \
  839.                     Continue anyway?"] in {
  840.         "yes" {}
  841.         "no" { return }
  842.     }
  843.     replaceString {}
  844.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {^[ \t]*%.*\r} 0]
  845.     replaceAll
  846.     
  847.     replaceString {}
  848.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {[ \t]+%.*} 0]
  849.     replaceAll
  850.     
  851.     replaceString {\1%}
  852.     eval select [search -f 1 -r 1 -i 1 -m 0 -- {([^\\](\\\\)*)%.*} 0]
  853.     replaceAll
  854. }
  855.  
  856. # Converts all straight quotes to their TeX equivalents.
  857. proc convertQuotes {} {
  858.     global searchNoisily
  859.     message "working╔"
  860.     watchCursor
  861.     set messageString "selection"
  862.     if {[set start [getPos]] == [set end [selEnd]]} {
  863.         set messageString "document"
  864.         set start 0
  865.         set end [maxPos]
  866.     }
  867.     set text [getText $start $end]
  868.     # Convert all left double quotes:
  869.     set convert1 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\"" $text {\1``} text]
  870.     # Convert all right double quotes:
  871.     set convert2 [regsub -all "\(\[\^\\\\\]\)\"" $text {\1''} text]
  872.     # Convert all left single quotes:
  873.     set convert3 [regsub -all "\(\^\|\[\ \r\t\(\[\{\]\)\'" $text {\1`} text]
  874.     if {$convert1 || $convert2 || $convert3} then {
  875.         replaceText $start $end $text
  876.         message "all quotes in $messageString converted"
  877.     } else {
  878.         if {$searchNoisily} {beep}
  879.         message "no quotes found in $messageString"
  880.     }
  881. }
  882.  
  883. # Returns true if the argument contains non-literal double dollar
  884. # signs, and false otherwise.
  885. proc containsDoubleDollarSigns {text} {
  886.     return [regexp {(^|[^\\])\$\$} $text]
  887. }
  888.  
  889. # Converts all $$...$$ pairs to \[...\] and returns the number of such 
  890. # pairs converted.  If the dollar signs are unbalanced, does nothing 
  891. # and returns -1.
  892. proc convertDoubleDollarSigns {} {
  893.     watchCursor
  894.     set messageString "selection"
  895.     if {[set start [getPos]] == [set end [selEnd]]} {
  896.         set messageString "document"
  897.         set start 0
  898.         set end [maxPos]
  899.     }
  900.     set text [getText $start $end]
  901.     set subs [regsub -all {(^|[^\\])\$\$([^$]*)\$\$} $text {\1\\[\2\\]} text]
  902.     if {[containsDoubleDollarSigns $text]} then {return -1}
  903.     if {$subs} then {
  904.         replaceText $start $end $text
  905.     }
  906.     return [expr $subs]
  907. }
  908.  
  909. # Returns true if the argument contains a non-literal dollar sign,
  910. # and false otherwise.
  911. proc containsSingleDollarSign {text} {
  912.     return [regexp {(^|[^\\])\$} $text]
  913. }
  914.  
  915. # Converts all $...$ pairs to \(...\), maintains the cursor position, 
  916. # and returns the number of such pairs converted.  If the dollar signs 
  917. # are unbalanced, does nothing and returns -1.
  918. proc convertSingleDollarSigns {} {
  919.     watchCursor
  920.     set subs1 0; set subs2 0; set subs3 0
  921.     set pos [getPos]; set pos2 $pos
  922.     if {[set start $pos] == [set end [selEnd]]} {
  923.         set isSelection 0
  924.         set start 0
  925.         set end [maxPos]
  926.         set text1 [getText $start $pos]
  927.         set subs1 [regsub -all {(^|[^\\])\$([^$]*)\$} $text1 {\1\\(\2\\)} text1]
  928.         # Is there a dollar sign left over?  If so, search backward for this
  929.         # dollar sign and prepare to do a substitution on the text to the right
  930.         # of this dollar sign.
  931.         if {[containsSingleDollarSign $text1]} then {
  932.             set searchString {[^\\]\$}
  933.             set searchResult [search -s -n -f 0 -m 0 -i 1 -r 1 $searchString [expr $pos-1]]
  934.             set pos2 [lindex $searchResult 0]
  935.             set text1 [string range $text1 0 [expr $pos2 + (2 * $subs1)]]
  936.             set pos [expr $pos + 2]
  937.         }
  938.         set text2 [getText $pos2 $end]
  939.         set subs2 [regsub -all {(^|[^\\])\$([^$]*)\$} $text2 {\1\\(\2\\)} text2]
  940.         # Is there a dollar sign left over?  If so, it's unbalanced.
  941.         if {[containsSingleDollarSign $text2]} then {return -1}
  942.         append text $text1 $text2
  943.     } else {
  944.         set isSelection 1
  945.         set text [getText $start $end]
  946.         set subs3 [regsub -all {(^|[^\\])\$([^$]*)\$} $text {\1\\(\2\\)} text]
  947.         # Is there a dollar sign left over?  If so, it's unbalanced.
  948.         if {[containsSingleDollarSign $text]} then {return -1}
  949.     }
  950.     if {$subs1 || $subs2 || $subs3} then {
  951.         replaceText $start $end $text
  952.         # If there is a selection, just put it back.  Otherwise, adjust the
  953.         # cursor position based on the number of substitutions.
  954.         if {$isSelection} then {
  955.             set end [getPos]
  956.             select $start $end
  957.         } else {
  958.             goto [expr $pos + (2 * $subs1)]
  959.         }
  960.     }
  961.     return [expr $subs1 + $subs2 + $subs3]
  962. }
  963.  
  964. proc convertDollarSigns {} {
  965.     global searchNoisily
  966.     if {[isSelection]} then {
  967.         set messageString "selection"
  968.     } else {
  969.         set messageString "document"
  970.     }
  971.     set subs2 [convertDoubleDollarSigns]
  972.     if {$subs2 == -1} then {
  973.         beep
  974.         alertnote "unmatched double dollar signs in $messageString"
  975.     } else {
  976.         set subs1 [convertSingleDollarSigns]
  977.         if {$subs1 == -1} then {
  978.             beep
  979.             alertnote "unmatched single dollar sign in $messageString"
  980.         } elseif {$subs1 == 0 && $subs2 == 0} then {
  981.             if {$searchNoisily} {beep}
  982.             message "no dollar signs found in $messageString"
  983.         } else {
  984.             message "$subs1 pairs of \$...\$ and $subs2 pairs of \$\$...\$\$ removed from $messageString"
  985.         }
  986.     }
  987. }
  988.  
  989. proc removeAuxiliaryFiles {} {
  990.     set word ""
  991.     set removeSilently 0
  992.     set currentWin [lindex [winNames -f] 0]
  993.     set currentDir [file dirname $currentWin]
  994.     set currentDoc [file tail $currentWin]
  995.     set docBasename [file rootname $currentDoc]
  996. #     set docExtension [file extension $currentDoc]
  997.     set extensions {.aux .bbl .dvi .glo .idx .ind .lof .log .lot \
  998.               .toc .blg .clg .ilg .ps}
  999.     foreach ext $extensions {
  1000.         message "Checking for *$ext files╔"
  1001.         set files [glob -nocomplain "$currentDir:*$ext"]
  1002.         foreach file $files {
  1003.             set word " more"
  1004.             if {$removeSilently} {
  1005.                 if {[catch {rm "$currentDir:*$ext"}]} then {
  1006.                     alertnote "not all \"*$ext\" files deleted"
  1007.                 }
  1008.                 break
  1009.             } else {
  1010.                 message ""
  1011.                 set filename [file tail $file]
  1012.                 case [buttonAlert "Remove \"$filename\"?" "yes" "no" {rm ext} {rm all} "cancel"] in {
  1013.                     "yes" {
  1014.                         message "Removing $filename╔"
  1015.                         if {[catch {removeFile "$currentDir:$filename"}]} then {
  1016.                             alertnote "\"$filename\" not deleted"
  1017.                         } else {
  1018.                             message $filename
  1019.                         }
  1020.                     }
  1021.                     "no" {}
  1022.                     "{rm ext}" {
  1023.                         if {[catch {rm "$currentDir:*$ext"}]} then {
  1024.                             alertnote "not all \"*$ext\" files deleted"
  1025.                         }
  1026.                         break
  1027.                     }
  1028.                     "{rm all}" {
  1029.                         if {[catch {rm "$currentDir:*$ext"}]} then {
  1030.                             alertnote "not all \"*$ext\" files deleted"
  1031.                         }
  1032.                         set removeSilently 1
  1033.                         break
  1034.                     }
  1035.                     "cancel" {return}
  1036.                 }
  1037.             }
  1038.         }
  1039.     }
  1040.     message "No$word files found"
  1041. }
  1042.  
  1043.  
  1044. #############################################################################
  1045. # Paragraph Mode Macros
  1046. #
  1047. #############################################################################
  1048.  
  1049. #--------------------------------------------------------------------------
  1050. # Documents:
  1051. #--------------------------------------------------------------------------
  1052.  
  1053. proc letter {} {
  1054.     set    preamble "\r\\address\{%\r"
  1055.     append preamble "    Ñ    \\\\    % insert your name here\r"
  1056.     append preamble "    Ñ    \\\\    % insert your address here\r"
  1057.     append preamble "    Ñ    \\\\    % insert more address here\r"
  1058.     append preamble "    Ñ          % insert city-state-zip here\r"
  1059.     append preamble "\}\r\r"
  1060.     append preamble "\\date\{Ñ\}  % optional\r"
  1061.     append preamble "\\signature\{Ñ\}\r\r"
  1062.     set    body "\r\\begin\{letter\}\{%\r"
  1063.     append body "    Ñ    \\\\    % insert addressee's name here\r"
  1064.     append body "    Ñ    \\\\    % insert addressee's address here\r"
  1065.     append body "    Ñ    \\\\    % insert more address here\r"
  1066.     append body "    Ñ          % insert addressee's city-state-zip here\r"
  1067.     append body "\}\r\r"
  1068.     append body "\\opening\{Dear Ñ,\}\r\r"
  1069.     if {[isEmptyFile]} then {
  1070.         append body "% BODY OF LETTER\r"
  1071.         append body "Ñ\r\r"
  1072.     } else {
  1073.         if {[isDocumentSelected]} then {
  1074.             set text [getSelect]
  1075. #             deleteText 0 [maxPos]
  1076.             append body "$text\r"
  1077.         } else {
  1078.             alertnote "nonempty file:  delete text or \'Select All\'\
  1079.                 from the Edit menu"
  1080.             return
  1081.         }
  1082.     }
  1083.     append body "\\closing\{Sincerely,\}\r\r"
  1084.     append body "\\encl\{Ñ\}\r"
  1085.     append body "\\cc\{Ñ\}\r\r"
  1086.     append body "\\end\{letter\}\r\r"
  1087.     insertDocument "letter" $preamble $body
  1088.     nextTabStop
  1089.     message "enter option (or leave blank)"
  1090. }
  1091. proc article {} {
  1092.     wrapDocument "article"
  1093.     nextTabStop
  1094.     message "enter option (or leave blank)"
  1095. }
  1096. proc report {} {
  1097.     wrapDocument "report"
  1098.     nextTabStop
  1099.     message "enter option (or leave blank)"
  1100. }
  1101. proc book {} {
  1102.     wrapDocument "book"
  1103.     nextTabStop
  1104.     message "enter option (or leave blank)"
  1105. }
  1106. proc slides {} {
  1107.     wrapDocument "slides"
  1108.     nextTabStop
  1109.     message "enter option (or leave blank)"
  1110. }
  1111. proc custom {} {
  1112.     catch {prompt "What documentclass?" "article"} documentType
  1113.     if {$documentType != "cancel"} then {
  1114.         wrapDocument "$documentType" 
  1115.         nextTabStop
  1116.         message "enter option (or leave blank)"
  1117.     }
  1118. }
  1119.  
  1120. proc getOption {} {
  1121.     catch {prompt "Choose an option:" "11pt" "" "10pt" "11pt" "12pt" "(-" \
  1122.             "letterpaper" "legalpaper" "executivepaper" "a4paper" "a5paper" \
  1123.             "b5paper" "(-" "landscape" "(-" "final" "draft" "(-" \
  1124.             "oneside" "twoside" "(-" "openright" "openany" "(-" \
  1125.             "onecolumn" "twocolumn" "(-" "notitlepage" "titlepage" \
  1126.                   "openbib" "(-" "leqno" "(-" "fleqn"} optionName
  1127.     if {$optionName != "cancel"} then {
  1128.         return $optionName
  1129.     } else {
  1130.         return ""
  1131.     }
  1132. }
  1133. proc insertOption {option} {
  1134.     global searchNoisily
  1135.     set searchString {\\documentclass}
  1136.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1137.     if {[llength $searchResult] == 0} then {
  1138.         if {$searchNoisily} {beep}
  1139.         message "can\'t find \\documentclass"
  1140.     } else {
  1141.         set nextCharPos [lindex $searchResult 1]
  1142.         goto $nextCharPos
  1143.         set nextChar [lookAt $nextCharPos]
  1144.         if {$nextChar == "\["} then {
  1145.             forwardChar
  1146.             insertText $option
  1147.             if {[lookAt [getPos]] != "\]"} then {
  1148.                 insertText ","
  1149.             }
  1150.         } elseif {$nextChar == "\{"} then {
  1151.             insertText "\[$option\]"
  1152.         } else {
  1153.             alertnote "unrecognizable \\documentclass statement"
  1154.         }
  1155.     }
  1156. }
  1157. proc options {} {
  1158.     set option [getOption]
  1159.     if {$option != ""} then {
  1160.         insertOption $option
  1161.     }
  1162. }
  1163. proc getPackage {} {
  1164.     catch {prompt "Choose a package:" "latexsym" "" \
  1165.                   "alltt" "amstex" "babel" "color" \
  1166.                   "graphics" "graphpap" "ifthen" "latexsym" "makeidx" \
  1167.                   "pict2e" "showidx"} packageName
  1168.     if {$packageName != "cancel"} then {
  1169.         return $packageName
  1170.     } else {
  1171.         return ""
  1172.     }
  1173. }
  1174. proc insertPackage {package} {
  1175.     global searchNoisily
  1176.     set begPos [getPos]
  1177.     set endPos [selEnd]
  1178.     append searchString {\\usepackage\{.*} $package {.*\}}
  1179.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1180.     if {[llength $searchResult] == 0} then {
  1181.         set searchString {\\documentclass(\[.*\])?\{.*\}}
  1182.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1183.         if {[llength $searchResult] == 0} then {
  1184.             if {$searchNoisily} {beep}
  1185.             message "can't find \\documentclass"
  1186.         } else {
  1187.             goto [lindex $searchResult 1]
  1188.             set txt "\r\\usepackage\{$package\}"
  1189.             set offset [string length $txt]
  1190.             set begPos [expr $begPos + $offset]
  1191.             set endPos [expr $endPos + $offset]
  1192.             insertText $txt
  1193.             select $begPos $endPos
  1194.         }
  1195.     } else {
  1196.         if {$searchNoisily} {beep}
  1197.         message "$package package already loaded"
  1198.     }
  1199. }
  1200. proc packages {} {
  1201.     set package [getPackage]
  1202.     if {$package != ""} then {
  1203.         insertPackage $package
  1204.     }
  1205. }
  1206. proc filecontents {} {
  1207.     global searchNoisily
  1208.     set searchString {\\documentclass}
  1209.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1210.     if {[llength $searchResult] == 0} then {
  1211.         if {$searchNoisily} {beep}
  1212.         message "can\'t find \\documentclass"
  1213.         return
  1214.     } else {
  1215.         set prompt "File to be included:"
  1216.         if {[catch {getfile $prompt} path]} then {
  1217.             return
  1218.         } else {
  1219.             set fd [open $path]
  1220.             set text [read $fd]
  1221.             close $fd
  1222.             regsub -all "\xa" $text "\xd" text
  1223.             goto 0
  1224.             set envName "filecontents"
  1225.             set envArg "{[file tail $path]}"
  1226.             replaceText 0 0 [buildEnvironment $envName $envArg "$text\r" "\r\r"]
  1227.             goto 0
  1228.             message "file included"
  1229.         }
  1230.     }
  1231. }
  1232.  
  1233. #--------------------------------------------------------------------------
  1234. # Page Layout:
  1235. #--------------------------------------------------------------------------
  1236.  
  1237. proc maketitle {} {
  1238.     global searchNoisily
  1239.     set searchString {\\document(class|style)(\[.*\])?\{.*\}}
  1240.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString 0]
  1241.     if {[llength $searchResult] == 0} then {
  1242.         if {$searchNoisily} {beep}
  1243.         message "can\'t find \\documentclass or \\documentstyle"
  1244.     } else {
  1245.         set searchPos [lindex $searchResult 1]
  1246.         set searchString {\\begin\{document\}}
  1247.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 $searchString $searchPos]
  1248.         if {[llength $searchResult] == 0} then {
  1249.             if {$searchNoisily} {beep}
  1250.             message "can\'t find \\begin\{document\}"
  1251.         } else {
  1252.             goto [lindex $searchResult 1]
  1253.             set currentPos [getPos]
  1254.             set txt "\r\r% Definition of title page:"
  1255.             append txt "\r\\title\{"
  1256.             append txt "\r\tÑ\r\}"
  1257.             append txt "\r\\author\{"
  1258.             append txt "\r\tÑ\t% insert author(s) here"
  1259.             append txt "\r\}"
  1260.             append txt "\r\\date\{Ñ\}\t% optional"
  1261.             append txt "\r\r\\maketitle"
  1262.             insertText $txt
  1263.             goto $currentPos
  1264.             nextTabStop
  1265.             message "insert title"
  1266.         }
  1267.     }
  1268. }
  1269. proc abstract {} { doWrapEnvironment "abstract" }
  1270. proc titlepage {} { doWrapEnvironment "titlepage" }
  1271. proc getPagestyle {} {
  1272.     catch {prompt "Choose a pagestyle:" "plain" "" "plain" "empty" \
  1273.                   "headings" "myheadings"} pagestyleName
  1274.     if {$pagestyleName != "cancel"} then {
  1275.         return $pagestyleName
  1276.     } else {
  1277.         return ""
  1278.     }
  1279. }
  1280. proc pagestyle {} {
  1281.     set pagestyleName [getPagestyle]
  1282.     if {$pagestyleName != ""} then {
  1283.         openingCarriageReturn
  1284.         insertObject "\\pagestyle\{$pagestyleName\}"
  1285.         closingCarriageReturn
  1286.     }
  1287. }
  1288. proc thispagestyle {} {
  1289.     set pagestyleName [getPagestyle]
  1290.     if {$pagestyleName != ""} then {
  1291.         openingCarriageReturn
  1292.         insertObject "\\thispagestyle\{$pagestyleName\}"
  1293.         closingCarriageReturn
  1294.     }
  1295. }
  1296. proc getPagenumberingStyle {} {
  1297.     catch {prompt "Choose a pagenumbering style:" "arabic" "" "arabic" \
  1298.                   "roman" "Roman" "alph" "Alph"} pagenumberingStyle
  1299.     if {$pagenumberingStyle != "cancel"} then {
  1300.         return $pagenumberingStyle
  1301.     } else {
  1302.         return ""
  1303.     }
  1304. }
  1305. proc pagenumbering {} {
  1306.     set pagenumberingStyle [getPagenumberingStyle]
  1307.     if {$pagenumberingStyle != ""} then {
  1308.         openingCarriageReturn
  1309.         insertObject "\\pagenumbering\{$pagenumberingStyle\}"
  1310.         closingCarriageReturn
  1311.     }
  1312. }
  1313. proc twocolumn {} {
  1314.     openingCarriageReturn
  1315.     insertObject "\\twocolumn"
  1316.     closingCarriageReturn
  1317. }
  1318. proc onecolumn {} {
  1319.     openingCarriageReturn
  1320.     insertObject "\\onecolumn"
  1321.     closingCarriageReturn
  1322. }
  1323.  
  1324. #--------------------------------------------------------------------------
  1325. # Sectioning:
  1326. #--------------------------------------------------------------------------
  1327.  
  1328. proc part {} {
  1329.     if {[wrapObject "\\part{" "}Ñ"]} then {
  1330.         message "don't forget the label"
  1331.     } else {
  1332.         message "type the part name and don't forget the label"
  1333.     }
  1334. }
  1335. proc chapter {} {
  1336.     if {[wrapObject "\\chapter{" "}Ñ"]} then {
  1337.         message "don't forget the label"
  1338.     } else {
  1339.         message "type the chapter name and don't forget the label"
  1340.     }
  1341. }
  1342. proc section {} {
  1343.     if {[wrapObject "\\section{" "}Ñ"]} then {
  1344.         message "don't forget the label"
  1345.     } else {
  1346.         message "type the section name and don't forget the label"
  1347.     }
  1348. }
  1349. proc subsection {} {
  1350.     if {[wrapObject "\\subsection{" "}Ñ"]} then {
  1351.         message "don't forget the label"
  1352.     } else {
  1353.         message "type the subsection name and don't forget the label"
  1354.     }
  1355. }
  1356. proc subsubsection {} {
  1357.     if {[wrapObject "\\subsubsection{" "}Ñ"]} then {
  1358.         message "don't forget the label"
  1359.     } else {
  1360.         message "type the subsubsection name and don't forget the label"
  1361.     }
  1362. }
  1363. proc paragraph {} {
  1364.     if {[wrapObject "\\paragraph{" "}Ñ"]} then {
  1365.         message "don't forget the label"
  1366.     } else {
  1367.         message "type the paragraph name and don't forget the label"
  1368.     }
  1369. }
  1370. proc subparagraph {} {
  1371.     if {[wrapObject "\\subparagraph{" "}Ñ"]} then {
  1372.         message "don't forget the label"
  1373.     } else {
  1374.         message "type the subparagraph name and don't forget the label"
  1375.     }
  1376. }
  1377. proc appendix {} {insertObject "\\appendix"}
  1378.  
  1379. #--------------------------------------------------------------------------
  1380. # Text Style:
  1381. #--------------------------------------------------------------------------
  1382.  
  1383. proc emph {} {
  1384.     if {[wrapObject "\\emph{" "}Ñ"]} then {
  1385.         message "selected text has been emphasized"
  1386.     } else {
  1387.         message "enter text to be emphasized"
  1388.     }
  1389. }
  1390. proc textup {} {
  1391.     if {[wrapObject "\\textup{" "}Ñ"]} then {
  1392.         message "selected text has upright shape"
  1393.     } else {
  1394.         message "enter text to have upright shape"
  1395.     }
  1396. }
  1397. proc textit {} {
  1398.     if {[wrapObject "\\textit{" "}Ñ"]} then {
  1399.         message "selected text has italic shape"
  1400.     } else {
  1401.         message "enter text to have italic shape"
  1402.     }
  1403. }
  1404. proc textsl {} {
  1405.     if {[wrapObject "\\textsl{" "}Ñ"]} then {
  1406.         message "selected text has slanted shape"
  1407.     } else {
  1408.         message "enter text to have slanted shape"
  1409.     }
  1410. }
  1411. proc textsc {} {
  1412.     if {[wrapObject "\\textsc{" "}Ñ"]} then {
  1413.         message "selected text has small caps shape"
  1414.     } else {
  1415.         message "enter text to have small caps shape"
  1416.     }
  1417. }
  1418. proc textmd {} {
  1419.     if {[wrapObject "\\textmd{" "}Ñ"]} then {
  1420.         message "selected text has been set in medium series"
  1421.     } else {
  1422.         message "enter text to be set in medium series"
  1423.     }
  1424. }
  1425. proc textbf {} {
  1426.     if {[wrapObject "\\textbf{" "}Ñ"]} then {
  1427.         message "selected text has been set in bold series"
  1428.     } else {
  1429.         message "enter text to be set in bold series"
  1430.     }
  1431. }
  1432. proc textrm {} {
  1433.     if {[wrapObject "\\textrm{" "}Ñ"]} then {
  1434.         message "selected text has been set with roman family"
  1435.     } else {
  1436.         message "enter text to be set using roman family"
  1437.     }
  1438. }
  1439. proc textsf {} {
  1440.     if {[wrapObject "\\textsf{" "}Ñ"]} then {
  1441.         message "selected text has been set with sans serif family"
  1442.     } else {
  1443.         message "enter text to be set using sans serif family"
  1444.     }
  1445. }
  1446. proc texttt {} {
  1447.     if {[wrapObject "\\texttt{" "}Ñ"]} then {
  1448.         message "selected text has been set with typewriter family"
  1449.     } else {
  1450.         message "enter text to be set using typewriter family"
  1451.     }
  1452. }
  1453. proc textnormal {} {
  1454.     if {[wrapObject "\\textnormal{" "}Ñ"]} then {
  1455.         message "selected text has been set with normal style"
  1456.     } else {
  1457.         message "enter text to be set using normal style"
  1458.     }
  1459. }
  1460.  
  1461. #--------------------------------------------------------------------------
  1462. # Text Size:
  1463. #--------------------------------------------------------------------------
  1464.  
  1465. proc tiny {} {
  1466.     if {[wrapObject "{\\tiny " "}Ñ"]} then {
  1467.         message "tiny text set"
  1468.     } else {
  1469.         message "enter tiny text"
  1470.     }
  1471. }
  1472. proc scriptsize {} {
  1473.     if {[wrapObject "{\\scriptsize " "}Ñ"]} then {
  1474.         message "scriptsize text set"
  1475.     } else {
  1476.         message "enter scriptsize text"
  1477.     }
  1478. }
  1479. proc footnotesize {} {
  1480.     if {[wrapObject "{\\footnotesize " "}Ñ"]} then {
  1481.         message "footnotesize text set"
  1482.     } else {
  1483.         message "enter footnotesize text"
  1484.     }
  1485. }
  1486. proc small {} {
  1487.     if {[wrapObject "{\\small " "}Ñ"]} then {
  1488.         message "small text set"
  1489.     } else {
  1490.         message "enter small text"
  1491.     }
  1492. }
  1493. proc normalsize {} {
  1494.     if {[wrapObject "{\\normalsize " "}Ñ"]} then {
  1495.         message "normalsize text set"
  1496.     } else {
  1497.         message "enter normalsize text"
  1498.     }
  1499. }
  1500. proc large {} {
  1501.     if {[wrapObject "{\\large " "}Ñ"]} then {
  1502.         message "large text set"
  1503.     } else {
  1504.         message "enter large text"
  1505.     }
  1506. }
  1507. proc Large {} {
  1508.     if {[wrapObject "{\\Large " "}Ñ"]} then {
  1509.         message "Large text set"
  1510.     } else {
  1511.         message "enter Large text"
  1512.     }
  1513. }
  1514. proc LARGE {} {
  1515.     if {[wrapObject "{\\LARGE " "}Ñ"]} then {
  1516.         message "LARGE text set"
  1517.     } else {
  1518.         message "enter LARGE text"
  1519.     }
  1520. }
  1521. proc huge {} {
  1522.     if {[wrapObject "{\\huge " "}Ñ"]} then {
  1523.         message "huge text set"
  1524.     } else {
  1525.         message "enter huge text"
  1526.     }
  1527. }
  1528. proc Huge {} {
  1529.     if {[wrapObject "{\\Huge " "}Ñ"]} then {
  1530.         message "Huge text set"
  1531.     } else {
  1532.         message "enter Huge text"
  1533.     }
  1534. }
  1535.  
  1536. #--------------------------------------------------------------------------
  1537. # International:
  1538. #--------------------------------------------------------------------------
  1539.  
  1540. proc {ÿ} {} {
  1541.     if {[wrapObject "\\`{" "}Ñ"]} then {
  1542.         message "accent set"
  1543.     } else {
  1544.         message "enter single character"
  1545.     }
  1546. }
  1547. proc {ù} {} {
  1548.     if {[wrapObject "\\'{" "}Ñ"]} then {
  1549.         message "accent set"
  1550.     } else {
  1551.         message "enter single character"
  1552.     }
  1553. }
  1554. proc {Ö} {} {
  1555.     if {[wrapObject "\\^{" "}Ñ"]} then {
  1556.         message "accent set"
  1557.     } else {
  1558.         message "enter single character"
  1559.     }
  1560. }
  1561. proc {Ü} {} {
  1562.     if {[wrapObject "\\\"{" "}Ñ"]} then {
  1563.         message "accent set"
  1564.     } else {
  1565.         message "enter single character"
  1566.     }
  1567. }
  1568. proc {¢} {} {
  1569.     if {[wrapObject "\\~{" "}Ñ"]} then {
  1570.         message "accent set"
  1571.     } else {
  1572.         message "enter single character"
  1573.     }
  1574. }
  1575. proc {ì} {} {insertObject "\\c\{c\}"}
  1576. proc {é} {} {insertObject "\\c\{C\}"}
  1577. proc {╧} {} {insertObject "\\oe"}
  1578. proc {╬} {} {insertObject "\\OE"}
  1579. proc {╛} {} {insertObject "\\ae"}
  1580. proc {«} {} {insertObject "\\AE"}
  1581. proc {î} {} {insertObject "\\aa"}
  1582. proc {ü} {} {insertObject "\\AA"}
  1583. proc {┐} {} {insertObject "\\o"}
  1584. proc {»} {} {insertObject "\\O"}
  1585. proc {º} {} {insertObject "\\ss"}
  1586. proc {└} {} {insertObject "?`"}
  1587. proc {┴} {} {insertObject "!`"}
  1588.  
  1589. #--------------------------------------------------------------------------
  1590. # Environments:
  1591. #--------------------------------------------------------------------------
  1592.  
  1593. proc enumerate {} {
  1594.     global promptNoisily useStatusBar
  1595.     set envName "enumerate"
  1596.     if {$promptNoisily && $useStatusBar} {beep}
  1597.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1598.     if {$numberItems == "cancel"} then {
  1599.         return
  1600.     } elseif {![isPositiveInteger $numberItems]} then {
  1601.         beep
  1602.         message "invalid input:  unsigned, postive integer required"
  1603.         return
  1604.     }
  1605.     if {$numberItems} then {
  1606.         set body "\t\\item  Ñ"
  1607.         for {set i 1} {$i < $numberItems} {incr i} {
  1608.             append body "\r\r\t\\item  Ñ"
  1609.         }
  1610.         append body "\r"
  1611.     } else {
  1612.         set body "\tÑ\r"
  1613.     }
  1614.     if {[insertEnvironment $envName "" $body]} then {
  1615.         nextTabStop
  1616.         message "type first item"
  1617.     }
  1618. }
  1619. proc itemize {} {
  1620.     global promptNoisily useStatusBar
  1621.     set envName "itemize"
  1622.     if {$promptNoisily && $useStatusBar} {beep}
  1623.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1624.     if {$numberItems == "cancel"} then {
  1625.         return
  1626.     } elseif {![isPositiveInteger $numberItems]} then {
  1627.         beep
  1628.         message "invalid input:  unsigned, postive integer required"
  1629.         return
  1630.     }
  1631.     if {$numberItems} then {
  1632.         set body "\t\\item  Ñ"
  1633.         for {set i 1} {$i < $numberItems} {incr i} {
  1634.             append body "\r\r\t\\item  Ñ"
  1635.         }
  1636.         append body "\r"
  1637.     } else {
  1638.         set body "\tÑ\r"
  1639.     }
  1640.     if {[insertEnvironment $envName "" $body]} then {
  1641.         nextTabStop
  1642.         message "type first item"
  1643.     }
  1644. }
  1645. proc description {} {
  1646.     global promptNoisily useStatusBar
  1647.     set envName "description"
  1648.     if {$promptNoisily && $useStatusBar} {beep}
  1649.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1650.     if {$numberItems == "cancel"} then {
  1651.         return
  1652.     } elseif {![isPositiveInteger $numberItems]} then {
  1653.         beep
  1654.         message "invalid input:  unsigned, postive integer required"
  1655.         return
  1656.     }
  1657.     if {$numberItems} then {
  1658.         set body "\t\\item\[Ñ\]  Ñ"
  1659.         for {set i 1} {$i < $numberItems} {incr i} {
  1660.             append body "\r\r\t\\item\[Ñ\]  Ñ"
  1661.         }
  1662.         append body "\r"
  1663.     } else {
  1664.         set body "\tÑ\r"
  1665.     }
  1666.     if {[insertEnvironment $envName "" $body]} then {
  1667.         nextTabStop
  1668.         message "type first item label"
  1669.     }
  1670. }
  1671. proc thebibliography {} {
  1672.     global promptNoisily useStatusBar
  1673.     set envName "thebibliography"
  1674.     if {$promptNoisily && $useStatusBar} {beep}
  1675.     catch {sPrompt "$envName:  how many items?" 3} numberItems
  1676.     if {$numberItems == "cancel"} then {
  1677.         return
  1678.     } elseif {![isPositiveInteger $numberItems]} then {
  1679.         beep
  1680.         message "invalid input:  unsigned, postive integer required"
  1681.         return
  1682.     }
  1683.     set arg "{9}"
  1684.     if {$numberItems} then {
  1685.         if {$numberItems > 9} then {set arg "{99}"}
  1686.         set body "\t\\bibitem{Ñ}  Ñ"
  1687.         for {set i 1} {$i < $numberItems} {incr i} {
  1688.             append body "\r\r\t\\bibitem{Ñ}  Ñ"
  1689.         }
  1690.         append body "\r"
  1691.     } else {
  1692.         set body "\tÑ\r"
  1693.     }
  1694.     if {[insertEnvironment $envName $arg $body]} then {
  1695.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(9)+} [getPos]]
  1696.         eval select $searchResult
  1697.         message "Change the length of the key field?"
  1698.     }
  1699. }
  1700. proc slide {} { doWrapEnvironment "slide" }
  1701. proc overlay {} { doWrapEnvironment "overlay" }
  1702. proc note {} { doWrapEnvironment "note" }
  1703. proc figure {} {
  1704.     global useBoxMacro boxMacroName
  1705.     set envName "figure"
  1706.     set envArg "tbp"
  1707.     set arg "\[$envArg\]"
  1708.     set body ""
  1709.     if {$useBoxMacro} then {
  1710.         append body "\t\\centerline{\\$boxMacroName{Ñ}}\r"
  1711.     }
  1712.     append body "\t\\caption{Ñ}\r"
  1713.     append body "\t\\protect\\label{Ñ}\r"
  1714.     if {$useBoxMacro} then {
  1715.         if {![insertEnvironment $envName $arg $body]} then {return}
  1716.     } else {
  1717.         wrapEnvironment $envName $arg $body
  1718.     }
  1719.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1720.     eval select $searchResult
  1721.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1722. }
  1723. proc table {} {
  1724.     set envName "table"
  1725.     set envArg "tbp"
  1726.     # The following statement puts the caption at the top:
  1727.     set arg "\[$envArg\]\r[getIndentation [getPos]]\t\\caption{Ñ}"
  1728.     # The following two statements put the caption at the bottom:
  1729. #     set arg "\[$envArg\]"
  1730. #     set body "\t\\caption{Ñ}\r"
  1731.     append body "\t\\protect\\label{Ñ}\r"
  1732.     wrapEnvironment $envName $arg $body
  1733.     set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 "$envArg" [getPos]]
  1734.     eval select $searchResult
  1735.     message "Modify this argument?  (t=top; b=bottom; p=page; h=here; !=try harder)"
  1736. }
  1737. proc buildRow {jmax} {
  1738.     set txt "Ñ"
  1739.     for {set j 1} {$j < $jmax} {incr j} {
  1740.         append txt " & Ñ"
  1741.     }
  1742.     return $txt
  1743. }
  1744. proc tabular {} {
  1745.     global promptNoisily useStatusBar
  1746.     set envName "tabular"
  1747.     if {$promptNoisily && $useStatusBar} {beep}
  1748.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  1749.     if {$numberRows == "cancel"} then {
  1750.         return
  1751.     } elseif {![isPositiveInteger $numberRows]} then {
  1752.         beep
  1753.         message "invalid input:  unsigned, postive integer required"
  1754.         return
  1755.     }
  1756.     if {$promptNoisily && $useStatusBar} {beep}
  1757.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  1758.     if {$numberCols == "cancel"} then {
  1759.         return
  1760.     } elseif {![isPositiveInteger $numberCols]} then {
  1761.         beep
  1762.         message "invalid input:  unsigned, postive integer required"
  1763.         return
  1764.     }
  1765.     set arg "{|"
  1766.     for {set j 1} {$j <= $numberCols} {incr j} {
  1767.         append arg "c|"
  1768.     }
  1769.     append arg "}"
  1770.     set body "\t\\hline\r"
  1771.     for {set i 1} {$i <= $numberRows} {incr i} {
  1772.         append body "\t[buildRow $numberCols]"
  1773.         append body "  \\\\\r\t\\hline\r"
  1774.     }
  1775.     if {[insertEnvironment $envName $arg $body]} then {
  1776.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {(c|\|)+} [getPos]]
  1777.         select [lindex $searchResult 0] [lindex $searchResult 1]
  1778.         message "Modify this argument?"
  1779.     }
  1780. }
  1781. proc verbatim {} { doWrapEnvironment "verbatim" }
  1782. proc quote {} { doWrapEnvironment "quote" }
  1783. proc quotation {} { doWrapEnvironment "quotation" }
  1784. proc verse {} { doWrapEnvironment "verse" }
  1785. proc flushleft {} { doWrapEnvironment "flushleft" }
  1786. proc center {} { doWrapEnvironment "center" }
  1787. proc flushright {} { doWrapEnvironment "flushright" }
  1788. proc general {} {
  1789.     catch {prompt "What environment?" ""} environmentName
  1790.     if {$environmentName != "cancel"} {
  1791.         doWrapEnvironment "$environmentName"
  1792.     }
  1793. }
  1794.  
  1795. #--------------------------------------------------------------------------
  1796. # Boxes:
  1797. #--------------------------------------------------------------------------
  1798.  
  1799. proc mbox {} {
  1800.     if {[wrapObject "\\mbox{" "}Ñ"]} then {
  1801.         message "mbox set"
  1802.     } else {
  1803.         message "enter text"
  1804.     }
  1805. }
  1806. proc makebox {} {
  1807.     if {[wrapObject "\\makebox\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1808.         message "makebox set; enter the width and position"
  1809.     } else {
  1810.         message "enter the width and position of the makebox, then the text"
  1811.     }
  1812. }
  1813. proc fbox {} {
  1814.     if {[wrapObject "\\fbox{" "}Ñ"]} then {
  1815.         message "fbox set"
  1816.     } else {
  1817.         message "enter text"
  1818.     }
  1819. }
  1820. proc framebox {} {
  1821.     if {[wrapObject "\\framebox\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1822.         message "framebox set; enter the width and position"
  1823.     } else {
  1824.         message "enter the width and position of the framebox, then the text"
  1825.     }
  1826. }
  1827. proc newsavebox {} {
  1828.     if {[wrapObject "\\newsavebox{" "}Ñ"]} then {
  1829.         message "newsavebox defined"
  1830.     } else {
  1831.         message "enter the command name of the sbox or savebox"
  1832.     }
  1833. }
  1834. proc sbox {} {
  1835.     if {[wrapObject "\\sbox{Ñ}{" "}Ñ"]} then {
  1836.         message "sbox set; enter the command name"
  1837.     } else {
  1838.         message "enter the command name of the sbox, then the text"
  1839.     }
  1840. }
  1841. proc savebox {} {
  1842.     if {[wrapObject "\\savebox{Ñ}\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1843.         message "savebox set; enter the command name"
  1844.     } else {
  1845.         message "enter the command name of the savebox"
  1846.     }
  1847. }
  1848. proc usebox {} {
  1849.     if {[wrapObject "\\usebox{" "}Ñ"]} then {
  1850.         message "usebox declared"
  1851.     } else {
  1852.         message "enter the command name of the sbox or savebox"
  1853.     }
  1854. }
  1855. proc raisebox {} {
  1856.     if {[wrapObject "\\raisebox{Ñ}\[Ñ\]\[Ñ\]{" "}Ñ"]} then {
  1857.         message "raisebox set; enter the displacement"
  1858.     } else {
  1859.         message "enter the displacement of the raisebox"
  1860.     }
  1861. }
  1862. proc parbox {} {
  1863.     if {[wrapObject "\\parbox\[Ñ\]\{Ñ\}{" "}Ñ"]} then {
  1864.         message "parbox set; enter the position and width"
  1865.     } else {
  1866.         message "enter the position \[b|c|t\] and width of the parbox, then the text"
  1867.     }
  1868. }
  1869. proc minipage {} {
  1870.     set arg "\[Ñ\]{Ñ}"
  1871.     wrapEnvironment "minipage" $arg ""
  1872.     nextTabStop
  1873.     message "enter the position \[b|c|t\] of the minipage, then the width"
  1874. }
  1875. proc rule {} {
  1876.     insertObject "\\rule\[Ñ\]\{Ñ\}{Ñ}Ñ"
  1877.     nthTabStop -4
  1878.     message "enter the displacement of the rule, then width and height"
  1879. }
  1880.  
  1881. #--------------------------------------------------------------------------
  1882. # Misc:
  1883. #--------------------------------------------------------------------------
  1884.  
  1885. proc ldots {} {insertObject "\\ldots"}
  1886. proc {en-dash} {} {insertObject "--"}
  1887. proc {em-dash} {} {insertObject "---"}
  1888. proc texLogo {} {insertObject "\\TeX"}
  1889. proc latexLogo {} {insertObject "\\LaTeX"}
  1890. proc latex2eLogo {} {insertObject "\\LaTeXe"}
  1891. proc today {} {insertObject "\\today"}
  1892. proc dag {} {insertObject "\\dag"}
  1893. proc ddag {} {insertObject "\\ddag"}
  1894. proc sectionMark {} {insertObject "\\S"}
  1895. proc paragraphMark {} {insertObject "\\P"}
  1896. proc copyright {} {insertObject "\\copyright"}
  1897. proc pounds {} {insertObject "\\pounds"}
  1898. proc quotes {} {
  1899.     if {[wrapObject "`" "'Ñ"]} then {
  1900.         message "text quoted"
  1901.     } else {
  1902.         message "enter text"
  1903.     }
  1904. }
  1905. proc dblQuotes {} {
  1906.     if {[wrapObject "``" "''Ñ"]} then {
  1907.         message "text double quoted"
  1908.     } else {
  1909.         message "enter text"
  1910.     }
  1911. }
  1912. proc marginalNote {} {
  1913.     if {[wrapObject "\\marginpar{" "}Ñ"]} then {
  1914.         message "marginal note set"
  1915.     } else {
  1916.         message "enter marginal note"
  1917.     }
  1918. }
  1919. proc footnote {} {
  1920.     if {[wrapObject "\\footnote{" "}Ñ"]} then {
  1921.         message "footnote set"
  1922.     } else {
  1923.         message "enter footnote"
  1924.     }
  1925. }
  1926. proc label {} {
  1927.     if {[wrapObject "\\label{" "}Ñ"]} then {
  1928.         message "label defined"
  1929.     } else {
  1930.         message "enter label"
  1931.     }
  1932. }
  1933. proc ref {} { 
  1934.     if {[wrapObject "\\ref{" "}Ñ"]} then {
  1935.         message "cross-reference made"
  1936.     } else {
  1937.         message "enter cross-reference"
  1938.     }
  1939. }
  1940. proc pageref {} { 
  1941.     if {[wrapObject "\\pageref{" "}Ñ"]} then {
  1942.         message "page reference made"
  1943.     } else {
  1944.         message "enter page reference"
  1945.     }
  1946. }
  1947. proc cite {} {
  1948.     if {[wrapObject "\\cite{" "}Ñ"]} then {
  1949.         message "citation made"
  1950.     } else {
  1951.         message "enter citation"
  1952.     }
  1953. }
  1954. # Insert an \item or a \bibitem, depending on the context.
  1955. proc insertItem {} {
  1956. #     global TeXmodeVars
  1957. #     if {$TeXmodeVars(expertMode) == 0} then {
  1958. #         if {![isInDocument]} then {
  1959. #             if {$TeXmodeVars(searchNoisily)} {beep}
  1960. #             case [askyesno "The cursor is not in the document environment.\
  1961. #                             \rContinue the operation?"] in {
  1962. #                 "yes" {}
  1963. #                 "no" {error "insertItem:  out of context"}
  1964. #             }
  1965. #         }
  1966. #     }
  1967.     set command [eval getText [searchEnvironment]]
  1968.     set environment [extractCommandArg $command]
  1969.     case $environment in {
  1970.         {itemize enumerate} {
  1971.             set text "\\item  Ñ"
  1972.         }
  1973.         "description" {
  1974.             set text "\\item\[Ñ\]  Ñ"
  1975.         }
  1976.         "thebibliography" {
  1977.             set text "\\bibitem{Ñ}  Ñ"
  1978.         }
  1979.         default {
  1980.             beep
  1981.             message "insertItem: cursor in $environment environment"
  1982.             return
  1983.         }
  1984.     }
  1985.     set pos [getPos]
  1986.     # Indentation should mirror that of an existing \item
  1987.     # (if it exists)
  1988.     insertText [openingCarriageReturn]$text
  1989.     goto $pos
  1990.     nextTabStop
  1991. }
  1992.  
  1993.  
  1994. #############################################################################
  1995. # Math Mode Macros
  1996. #
  1997. #############################################################################
  1998.  
  1999. #--------------------------------------------------------------------------
  2000. # Math Modes:
  2001. #--------------------------------------------------------------------------
  2002.  
  2003. proc texMath {} {
  2004.     checkMathMode "texMath" 0
  2005.     if {[wrapObject "$" "$Ñ"]} then {
  2006.         message "formula set"
  2007.     } else {
  2008.         message "enter formula"
  2009.     }
  2010. }
  2011. proc texDisplaymath {} {
  2012.     checkMathMode "texDisplaymath" 0
  2013.     if {[wrapObject "$$" "$$Ñ"]} then {
  2014.         message "displayed formula set"
  2015.     } else {
  2016.         message "enter displayed formula"
  2017.     }
  2018. }
  2019. proc latexMath {} {
  2020.     checkMathMode "latexMath" 0
  2021.     if {[wrapObject "\\( " " \\)Ñ"]} then {
  2022.         message "formula set"
  2023.     } else {
  2024.         message "enter formula"
  2025.     }
  2026. }
  2027. proc latexDisplaymath {} {
  2028.     checkMathMode "latexDisplaymath" 0
  2029.     if {[wrapObject "\\\[ " " \\\]Ñ"]} then {
  2030.         message "displayed formula set"
  2031.     } else {
  2032.         message "enter displayed formula"
  2033.     }
  2034. }
  2035.  
  2036. #--------------------------------------------------------------------------
  2037. # Math Style:
  2038. #--------------------------------------------------------------------------
  2039.  
  2040. proc mathit {} {
  2041.     checkMathMode "mathit" 1
  2042.     if {[wrapObject "\\mathit{" "}Ñ"]} then {
  2043.         message "selected text is math italic"
  2044.     } else {
  2045.         message "enter text to be math italic"
  2046.     }
  2047. }
  2048. proc mathrm {} {
  2049.     checkMathMode "mathrm" 1
  2050.     if {[wrapObject "\\mathrm{" "}Ñ"]} then {
  2051.         message "selected text is math roman"
  2052.     } else {
  2053.         message "enter text to be math roman"
  2054.     }
  2055. }
  2056. proc mathbf {} {
  2057.     checkMathMode "mathbf" 1
  2058.     if {[wrapObject "\\mathbf{" "}Ñ"]} then {
  2059.         message "selected text is math bold"
  2060.     } else {
  2061.         message "enter text to be math bold"
  2062.     }
  2063. }
  2064. proc mathsf {} {
  2065.     checkMathMode "mathsf" 1
  2066.     if {[wrapObject "\\mathsf{" "}Ñ"]} then {
  2067.         message "selected text is math sans serif"
  2068.     } else {
  2069.         message "enter text to be math sans serif"
  2070.     }
  2071. }
  2072. proc mathtt {} {
  2073.     checkMathMode "mathtt" 1
  2074.     if {[wrapObject "\\mathtt{" "}Ñ"]} then {
  2075.         message "selected text is math typewriter"
  2076.     } else {
  2077.         message "enter text to be math typewriter"
  2078.     }
  2079. }
  2080. proc mathcal {} {
  2081.     checkMathMode "mathcal" 1
  2082.     # Allow upper-case arguments only:
  2083.     if {[isSelection] && ![isUppercase]} then {
  2084.         alertnote "argument to \\mathcal must be uppercase"
  2085.         return
  2086.     }
  2087.     if {[wrapObject "\\mathcal{" "}Ñ"]} then {
  2088.         message "selected text is calligraphic"
  2089.     } else {
  2090.         message "enter text to be calligraphic (UPPERCASE letters only)"
  2091.     }
  2092. }
  2093. proc displaystyle {} {
  2094.     checkMathMode "displaystyle" 1
  2095.     if {[wrapObject "{\\displaystyle " "}Ñ"]} then {
  2096.         message "displaystyle set"
  2097.     } else {
  2098.         message "enter displaystyle text"
  2099.     }
  2100. }
  2101. proc textstyle {} {
  2102.     checkMathMode "textstyle" 1
  2103.     if {[wrapObject "{\\textstyle " "}Ñ"]} then {
  2104.         message "textstyle set"
  2105.     } else {
  2106.         message "enter textstyle text"
  2107.     }
  2108. }
  2109. proc scriptstyle {} {
  2110.     checkMathMode "scriptstyle" 1
  2111.     if {[wrapObject "{\\scriptstyle " "}Ñ"]} then {
  2112.         message "scriptstyle set"
  2113.     } else {
  2114.         message "enter scriptstyle text"
  2115.     }
  2116. }
  2117. proc scriptscriptstyle {} {
  2118.     checkMathMode "scriptscriptstyle" 1
  2119.     if {[wrapObject "{\\scriptscriptstyle " "}Ñ"]} then {
  2120.         message "scriptscriptstyle set"
  2121.     } else {
  2122.         message "enter scriptscriptstyle text"
  2123.     }
  2124. }
  2125.  
  2126. #--------------------------------------------------------------------------
  2127. # Math Environments:
  2128. #--------------------------------------------------------------------------
  2129.  
  2130. proc math {} { checkMathMode "math" 0; doWrapEnvironment "math" }
  2131. proc displaymath {} {
  2132.     checkMathMode "displaymath" 0
  2133.     doWrapEnvironment "displaymath"
  2134. }
  2135. proc equation {} {
  2136.     checkMathMode "equation" 0
  2137.     set envName "equation"
  2138.     set body "\t\\label{Ñ}\r"
  2139.     if {[wrapEnvironment $envName "" $body]} then {
  2140.         set msgText "equation wrapped"
  2141.     } else {
  2142.         set msgText "enter equation"
  2143.     }
  2144.     nextTabStop
  2145.     message $msgText
  2146. }
  2147. proc eqnarrayStar {} {
  2148.     global promptNoisily useStatusBar
  2149.     checkMathMode "eqnarrayStar" 0
  2150.     set envName "eqnarray*"
  2151.     if {$promptNoisily && $useStatusBar} {beep}
  2152.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2153.     if {$numberRows == "cancel"} then {
  2154.         return
  2155.     } elseif {![isPositiveInteger $numberRows]} then {
  2156.         beep
  2157.         message "invalid input:  unsigned, postive integer required"
  2158.         return
  2159.     }
  2160.     set row "\t[buildRow 3]"
  2161.     for {set i 1} {$i < $numberRows} {incr i} {
  2162.         append body $row
  2163.         append body "  \\\\\r"
  2164.     }
  2165.     append body $row
  2166.     append body "\r"
  2167.     if {[insertEnvironment $envName "" $body]} then {
  2168.         nextTabStop
  2169.         message "type first item"
  2170.     }
  2171. }
  2172. proc eqnarray {} {
  2173.     global promptNoisily useStatusBar
  2174.     checkMathMode "eqnarray" 0
  2175.     set envName "eqnarray"
  2176.     if {$promptNoisily && $useStatusBar} {beep}
  2177.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2178.     if {$numberRows == "cancel"} then {
  2179.         return
  2180.     } elseif {![isPositiveInteger $numberRows]} then {
  2181.         beep
  2182.         message "invalid input:  unsigned, postive integer required"
  2183.         return
  2184.     }
  2185.     set row "\t[buildRow 3]\r\t\\label{Ñ}"
  2186.     for {set i 1} {$i < $numberRows} {incr i} {
  2187.         append body $row
  2188.         append body "  \\\\\r"
  2189.     }
  2190.     append body $row
  2191.     append body "\r"
  2192.     if {[insertEnvironment $envName "" $body]} then {
  2193.         nextTabStop
  2194.         message "type first item"
  2195.     }
  2196. }
  2197. proc myArray {} {
  2198.     global promptNoisily useStatusBar
  2199.     checkMathMode "myArray" 1
  2200.     set envName "array"
  2201.     if {$promptNoisily && $useStatusBar} {beep}
  2202.     catch {sPrompt "$envName:  how many rows?" 3} numberRows
  2203.     if {$numberRows == "cancel"} then {
  2204.         return
  2205.     } elseif {![isPositiveInteger $numberRows]} then {
  2206.         beep
  2207.         message "invalid input:  unsigned, postive integer required"
  2208.         return
  2209.     }
  2210.     if {$promptNoisily && $useStatusBar} {beep}
  2211.     catch {sPrompt "$envName:  how many columns?" 3} numberCols
  2212.     if {$numberCols == "cancel"} then {
  2213.         return
  2214.     } elseif {![isPositiveInteger $numberCols]} then {
  2215.         beep
  2216.         message "invalid input:  unsigned, postive integer required"
  2217.         return
  2218.     }
  2219.     set arg "{"
  2220.     for {set j 1} {$j <= $numberCols} {incr j} {
  2221.         append arg "c"
  2222.     }
  2223.     append arg "}"
  2224.     set row "\t[buildRow $numberCols]"
  2225.     for {set i 1} {$i < $numberRows} {incr i} {
  2226.         append body $row
  2227.         append body "  \\\\\r"
  2228.     }
  2229.     append body $row
  2230.     append body "\r"
  2231.     if {[insertEnvironment $envName $arg $body]} then {
  2232.         set searchResult [search -s -n -f 1 -m 0 -i 1 -r 1 {c+} [getPos]]
  2233.         select [lindex $searchResult 0] [lindex $searchResult 1]
  2234.         message "Modify this argument?"
  2235.     }
  2236. }
  2237.  
  2238. #--------------------------------------------------------------------------
  2239. # Formulas:
  2240. #--------------------------------------------------------------------------
  2241.  
  2242. proc subscript {} {
  2243.     checkMathMode "subscript" 1
  2244.     if {[wrapObject "_{" "}Ñ"]} then {
  2245.         message "subscript set"
  2246.     } else {
  2247.         message "enter subscript"
  2248.     }
  2249. }
  2250. proc superscript {} {
  2251.     checkMathMode "superscript" 1
  2252.     if {[wrapObject "^{" "}Ñ"]} then {
  2253.         message "superscript set"
  2254.     } else {
  2255.         message "enter superscript"
  2256.     }
  2257. }
  2258. proc fraction {} {
  2259.     checkMathMode "fraction" 1
  2260.     set currentPos [getPos]
  2261.     if {[isSelection]} then {
  2262.         set selection [getSelect]
  2263.         set args [split $selection /]
  2264.         set len [llength $args]
  2265.         deleteText $currentPos [selEnd]
  2266.         if {$len == 1} then {
  2267.             insertObject "\\frac{$selection}{Ñ}Ñ"
  2268.             goto $currentPos
  2269.             nextTabStop
  2270.             message "enter denominator"
  2271.         } else {
  2272.             set firstArg [lindex $args 0]
  2273.             set restArgs [lrange $args 1 [expr $len-1]]
  2274.             insertObject "\\frac{$firstArg}{[join $restArgs /]}"
  2275.             if {$len > 2} {message "beware of multiple /"}
  2276.         }
  2277.     } else {
  2278.         insertObject "\\frac{Ñ}{Ñ}Ñ"
  2279.         goto $currentPos
  2280.         nextTabStop
  2281.         message "enter numerator"
  2282.     }
  2283. }
  2284. proc squareRoot {} {
  2285.     checkMathMode "squareRoot" 1
  2286.     if {[wrapObject "\\sqrt{" "}Ñ"]} then {
  2287.         message "square root set"
  2288.     } else {
  2289.         message "enter formula"
  2290.     }
  2291. }
  2292. proc nthRoot {} {
  2293.     checkMathMode "nthRoot" 1
  2294.     if {[wrapObject "\\sqrt\[Ñ\]{" "}Ñ"]} then {
  2295.         message "enter root"
  2296.     } else {
  2297.         message "enter root, then formula"
  2298.     }
  2299. }
  2300. proc oneParameter {} {
  2301.     checkMathMode "oneParameter" 1
  2302.     catch {prompt "Command name?" "sqrt"} commandName
  2303.     if {$commandName != "cancel"} {wrapObject "\\$commandName{" "}Ñ"}
  2304. }
  2305. proc twoParameters {} {
  2306.     checkMathMode "twoParameters" 1
  2307.     catch {prompt "Command name?" "frac"} commandName
  2308.     if {$commandName != "cancel"} then {
  2309.         set currentPos [getPos]
  2310.         if {[insertObject "\\$commandName{Ñ}{Ñ}Ñ"]} then {
  2311.             goto $currentPos
  2312.             nextTabStop
  2313.         }
  2314.     }
  2315. }
  2316.  
  2317. #--------------------------------------------------------------------------
  2318. # Greek:
  2319. #--------------------------------------------------------------------------
  2320.  
  2321. proc alpha {} {checkMathMode "alpha" 1; insertObject "\\alpha"}
  2322. proc beta {} {checkMathMode "beta" 1; insertObject "\\beta"}
  2323. proc gamma {} {checkMathMode "gamma" 1; insertObject "\\gamma"}
  2324. proc delta {} {checkMathMode "delta" 1; insertObject "\\delta"}
  2325. proc epsilon {} {checkMathMode "epsilon" 1; insertObject "\\epsilon"}
  2326. proc zeta {} {checkMathMode "zeta" 1; insertObject "\\zeta"}
  2327. proc eta {} {checkMathMode "eta" 1; insertObject "\\eta"}
  2328. proc theta {} {checkMathMode "theta" 1; insertObject "\\theta"}
  2329. proc iota {} {checkMathMode "iota" 1; insertObject "\\iota"}
  2330. proc kappa {} {checkMathMode "kappa" 1; insertObject "\\kappa"}
  2331. proc lambda {} {checkMathMode "lambda" 1; insertObject "\\lambda"}
  2332. proc mu {} {checkMathMode "mu" 1; insertObject "\\mu"}
  2333. proc nu {} {checkMathMode "nu" 1; insertObject "\\nu"}
  2334. proc xi {} {checkMathMode "xi" 1; insertObject "\\xi"}
  2335. proc omicron {} {checkMathMode "omicron" 1; insertObject "o"}
  2336. proc pi {} {checkMathMode "pi" 1; insertObject "\\pi"}
  2337. proc rho {} {checkMathMode "rho" 1; insertObject "\\rho"}
  2338. proc sigma {} {checkMathMode "sigma" 1; insertObject "\\sigma"}
  2339. proc tau {} {checkMathMode "tau" 1; insertObject "\\tau"}
  2340. proc upsilon {} {checkMathMode "upsilon" 1; insertObject "\\upsilon"}
  2341. proc phi {} {checkMathMode "phi" 1; insertObject "\\phi"}
  2342. proc chi {} {checkMathMode "chi" 1; insertObject "\\chi"}
  2343. proc psi {} {checkMathMode "psi" 1; insertObject "\\psi"}
  2344. proc omega {} {checkMathMode "omega" 1; insertObject "\\omega"}
  2345.  
  2346. proc Gamma {} {checkMathMode "Gamma" 1; insertObject "\\Gamma"}
  2347. proc Delta {} {checkMathMode "Delta" 1; insertObject "\\Delta"}
  2348. proc Theta {} {checkMathMode "Theta" 1; insertObject "\\Theta"}
  2349. proc Lambda {} {checkMathMode "Lambda" 1; insertObject "\\Lambda"}
  2350. proc Xi {} {checkMathMode "Xi" 1; insertObject "\\Xi"}
  2351. proc Pi {} {checkMathMode "Pi" 1; insertObject "\\Pi"}
  2352. proc Sigma {} {checkMathMode "Sigma" 1; insertObject "\\Sigma"}
  2353. proc Upsilon {} {checkMathMode "Upsilon" 1; insertObject "\\Upsilon"}
  2354. proc Phi {} {checkMathMode "Phi" 1; insertObject "\\Phi"}
  2355. proc Psi {} {checkMathMode "Psi" 1; insertObject "\\Psi"}
  2356. proc Omega {} {checkMathMode "Omega" 1; insertObject "\\Omega"}
  2357.  
  2358. proc varepsilon {} {checkMathMode "varepsilon" 1; insertObject "\\varepsilon"}
  2359. proc vartheta {} {checkMathMode "vartheta" 1; insertObject "\\vartheta"}
  2360. proc varpi {} {checkMathMode "varpi" 1; insertObject "\\varpi"}
  2361. proc varrho {} {checkMathMode "varrho" 1; insertObject "\\varrho"}
  2362. proc varsigma {} {checkMathMode "varsigma" 1; insertObject "\\varsigma"}
  2363. proc varphi {} {checkMathMode "varphi" 1; insertObject "\\varphi"}
  2364.  
  2365. #--------------------------------------------------------------------------
  2366. # Binary Ops:
  2367. #--------------------------------------------------------------------------
  2368.  
  2369. proc pm {} {checkMathMode "pm" 1; insertObject "\\pm"}
  2370. proc mp {} {checkMathMode "mp" 1; insertObject "\\mp"}
  2371. proc times {} {checkMathMode "times" 1; insertObject "\\times"}
  2372. proc div {} {checkMathMode "div" 1; insertObject "\\div"}
  2373. proc ast {} {checkMathMode "ast" 1; insertObject "\\ast"}
  2374. proc star {} {checkMathMode "star" 1; insertObject "\\star"}
  2375. proc circ {} {checkMathMode "circ" 1; insertObject "\\circ"}
  2376. proc bullet {} {checkMathMode "bullet" 1; insertObject "\\bullet"}
  2377. proc cdot {} {checkMathMode "cdot" 1; insertObject "\\cdot"}
  2378. proc cap {} {checkMathMode "cap" 1; insertObject "\\cap"}
  2379. proc cup {} {checkMathMode "cup" 1; insertObject "\\cup"}
  2380. proc uplus {} {checkMathMode "uplus" 1; insertObject "\\uplus"}
  2381. proc sqcap {} {checkMathMode "sqcap" 1; insertObject "\\sqcap"}
  2382. proc sqcup {} {checkMathMode "sqcup" 1; insertObject "\\sqcup"}
  2383. proc vee {} {checkMathMode "vee" 1; insertObject "\\vee"}
  2384. proc wedge {} {checkMathMode "wedge" 1; insertObject "\\wedge"}
  2385. proc setminus {} {checkMathMode "setminus" 1; insertObject "\\setminus"}
  2386. proc wr {} {checkMathMode "wr" 1; insertObject "\\wr"}
  2387. proc diamond {} {checkMathMode "diamond" 1; insertObject "\\diamond"}
  2388. proc bigtriangleup {} {
  2389.     checkMathMode "bigtriangleup" 1; insertObject "\\bigtriangleup"
  2390. }
  2391. proc bigtriangledown {} {
  2392.     checkMathMode "bigtriangledown" 1; insertObject "\\bigtriangledown"
  2393. }
  2394. proc triangleleft {} {
  2395.     checkMathMode "triangleleft" 1; insertObject "\\triangleleft"
  2396. }
  2397. proc triangleright {} {
  2398.     checkMathMode "triangleright" 1; insertObject "\\triangleright"
  2399. }
  2400. proc lhd {} {
  2401.     if {[isSymbolPackageLoaded]} then {
  2402.         checkMathMode "lhd" 1; insertObject "\\lhd"
  2403.     }
  2404. }
  2405. proc rhd {} {
  2406.     if {[isSymbolPackageLoaded]} then {
  2407.         checkMathMode "rhd" 1; insertObject "\\rhd"
  2408.     }
  2409. }
  2410. proc unlhd {} {
  2411.     if {[isSymbolPackageLoaded]} then {
  2412.         checkMathMode "unlhd" 1; insertObject "\\unlhd"
  2413.     }
  2414. }
  2415. proc unrhd {} {
  2416.     if {[isSymbolPackageLoaded]} then {
  2417.         checkMathMode "unrhd" 1; insertObject "\\unrhd"
  2418.     }
  2419. }
  2420. proc oplus {} {checkMathMode "oplus" 1; insertObject "\\oplus"}
  2421. proc ominus {} {checkMathMode "ominus" 1; insertObject "\\ominus"}
  2422. proc otimes {} {checkMathMode "otimes" 1; insertObject "\\otimes"}
  2423. proc oslash {} {checkMathMode "oslash" 1; insertObject "\\oslash"}
  2424. proc odot {} {checkMathMode "odot" 1; insertObject "\\odot"}
  2425. proc bigcirc {} {checkMathMode "bigcirc" 1; insertObject "\\bigcirc"}
  2426. proc dagger {} {checkMathMode "dagger" 1; insertObject "\\dagger"}
  2427. proc ddagger {} {checkMathMode "ddagger" 1; insertObject "\\ddagger"}
  2428. proc amalg {} {checkMathMode "amalg" 1; insertObject "\\amalg"}
  2429.  
  2430. #--------------------------------------------------------------------------
  2431. # Relations:
  2432. #--------------------------------------------------------------------------
  2433.  
  2434. proc leq {} {checkMathMode "leq" 1; insertObject "\\leq"}
  2435. proc prec {} {checkMathMode "prec" 1; insertObject "\\prec"}
  2436. proc preceq {} {checkMathMode "preceq" 1; insertObject "\\preceq"}
  2437. proc myLl {} {checkMathMode "myLl" 1; insertObject "\\ll"}
  2438. proc subset {} {checkMathMode "subset" 1; insertObject "\\subset"}
  2439. proc subseteq {} {checkMathMode "subseteq" 1; insertObject "\\subseteq"}
  2440. proc sqsubset {} {
  2441.     if {[isSymbolPackageLoaded]} then {
  2442.         checkMathMode "sqsubset" 1; insertObject "\\sqsubset"
  2443.     }
  2444. }
  2445. proc sqsubseteq {} {checkMathMode "sqsubseteq" 1; insertObject "\\sqsubseteq"}
  2446. proc in {} {checkMathMode "in" 1; insertObject "\\in"}
  2447. proc vdash {} {checkMathMode "vdash" 1; insertObject "\\vdash"}
  2448.  
  2449. proc geq {} {checkMathMode "geq" 1; insertObject "\\geq"}
  2450. proc succ {} {checkMathMode "succ" 1; insertObject "\\succ"}
  2451. proc succeq {} {checkMathMode "succeq" 1; insertObject "\\succeq"}
  2452. proc gg {} {checkMathMode "gg" 1; insertObject "\\gg"}
  2453. proc supset {} {checkMathMode "supset" 1; insertObject "\\supset"}
  2454. proc supseteq {} {checkMathMode "supseteq" 1; insertObject "\\supseteq"}
  2455. proc sqsupset {} {
  2456.     if {[isSymbolPackageLoaded]} then {
  2457.         checkMathMode "sqsupset" 1; insertObject "\\sqsupset"
  2458.     }
  2459. }
  2460. proc sqsupseteq {} {checkMathMode "sqsupseteq" 1; insertObject "\\sqsupseteq"}
  2461. proc ni {} {checkMathMode "ni" 1; insertObject "\\ni"}
  2462. proc dashv {} {checkMathMode "dashv" 1; insertObject "\\dashv"}
  2463.  
  2464. proc equiv {} {checkMathMode "equiv" 1; insertObject "\\equiv"}
  2465. proc sim {} {checkMathMode "sim" 1; insertObject "\\sim"}
  2466. proc simeq {} {checkMathMode "simeq" 1; insertObject "\\simeq"}
  2467. proc asymp {} {checkMathMode "asymp" 1; insertObject "\\asymp"}
  2468. proc approx {} {checkMathMode "approx" 1; insertObject "\\approx"}
  2469. proc cong {} {checkMathMode "cong" 1; insertObject "\\cong"}
  2470. proc neq {} {checkMathMode "neq" 1; insertObject "\\neq"}
  2471. proc doteq {} {checkMathMode "doteq" 1; insertObject "\\doteq"}
  2472. proc propto {} {checkMathMode "propto" 1; insertObject "\\propto"}
  2473.  
  2474. proc models {} {checkMathMode "models" 1; insertObject "\\models"}
  2475. proc perp {} {checkMathMode "perp" 1; insertObject "\\perp"}
  2476. proc mid {} {checkMathMode "mid" 1; insertObject "\\mid"}
  2477. proc parallel {} {checkMathMode "parallel" 1; insertObject "\\parallel"}
  2478. proc bowtie {} {checkMathMode "bowtie" 1; insertObject "\\bowtie"}
  2479. proc myJoin {} {
  2480.     if {[isSymbolPackageLoaded]} then {
  2481.         checkMathMode "myJoin" 1; insertObject "\\join"
  2482.     }
  2483. }
  2484. proc smile {} {checkMathMode "smile" 1; insertObject "\\smile"}
  2485. proc frown {} {checkMathMode "frown" 1; insertObject "\\frown"}
  2486.  
  2487. #--------------------------------------------------------------------------
  2488. # Arrows:
  2489. #--------------------------------------------------------------------------
  2490.  
  2491. proc leftarrow {} {checkMathMode "leftarrow" 1; insertObject "\\leftarrow"}
  2492. proc Leftarrow {} {checkMathMode "Leftarrow" 1; insertObject "\\Leftarrow"}
  2493. proc rightarrow {} {checkMathMode "rightarrow" 1; insertObject "\\rightarrow"}
  2494. proc Rightarrow {} {checkMathMode "Rightarrow" 1; insertObject "\\Rightarrow"}
  2495. proc leftrightarrow {} {
  2496.     checkMathMode "leftrightarrow" 1; insertObject "\\leftrightarrow"
  2497. }
  2498. proc Leftrightarrow {} {
  2499.     checkMathMode "Leftrightarrow" 1; insertObject "\\Leftrightarrow"
  2500. }
  2501. proc mapsto {} {checkMathMode "mapsto" 1; insertObject "\\mapsto"}
  2502. proc hookleftarrow {} {
  2503.     checkMathMode "hookleftarrow" 1; insertObject "\\hookleftarrow"
  2504. }
  2505. proc leftharpoonup {} {
  2506.     checkMathMode "leftharpoonup" 1; insertObject "\\leftharpoonup"
  2507. }
  2508. proc leftharpoondown {} {
  2509.     checkMathMode "leftharpoondown" 1; insertObject "\\leftharpoondown"
  2510. }
  2511. proc rightleftharpoons {} {
  2512.     checkMathMode "rightleftharpoons" 1; insertObject "\\rightleftharpoons"
  2513. }
  2514.  
  2515. proc longleftarrow {} {
  2516.     checkMathMode "longleftarrow" 1; insertObject "\\longleftarrow"
  2517. }
  2518. proc Longleftarrow {} {
  2519.     checkMathMode "Longleftarrow" 1; insertObject "\\Longleftarrow"
  2520. }
  2521. proc longrightarrow {} {
  2522.     checkMathMode "longrightarrow" 1; insertObject "\\longrightarrow"
  2523. }
  2524. proc Longrightarrow {} {
  2525.     checkMathMode "Longrightarrow" 1; insertObject "\\Longrightarrow"
  2526. }
  2527. proc longleftrightarrow {} {
  2528.     checkMathMode "longleftrightarrow" 1; insertObject "\\longleftrightarrow"
  2529. }
  2530. proc Longleftrightarrow {} {
  2531.     checkMathMode "Longleftrightarrow" 1; insertObject "\\Longleftrightarrow"
  2532. }
  2533. proc longmapsto {} {checkMathMode "longmapsto" 1; insertObject "\\longmapsto"}
  2534. proc hookrightarrow {} {
  2535.     checkMathMode "hookrightarrow" 1; insertObject "\\hookrightarrow"
  2536. }
  2537. proc rightharpoonup {} {
  2538.     checkMathMode "rightharpoonup" 1; insertObject "\\rightharpoonup"
  2539. }
  2540. proc rightharpoondown {} {
  2541.     checkMathMode "rightharpoondown" 1; insertObject "\\rightharpoondown"
  2542. }
  2543. proc leadsto {} {
  2544.     if {[isSymbolPackageLoaded]} then {
  2545.         checkMathMode "leadsto" 1; insertObject "\\leadsto"
  2546.     }
  2547. }
  2548. proc uparrow {} {checkMathMode "uparrow" 1; insertObject "\\uparrow"}
  2549. proc Uparrow {} {checkMathMode "Uparrow" 1; insertObject "\\Uparrow"}
  2550. proc downarrow {} {checkMathMode "downarrow" 1; insertObject "\\downarrow"}
  2551. proc Downarrow {} {checkMathMode "Downarrow" 1; insertObject "\\Downarrow"}
  2552. proc updownarrow {} {checkMathMode "updownarrow" 1; insertObject "\\updownarrow"}
  2553. proc Updownarrow {} {checkMathMode "Updownarrow" 1; insertObject "\\Updownarrow"}
  2554. proc nearrow {} {checkMathMode "nearrow" 1; insertObject "\\nearrow"}
  2555. proc searrow {} {checkMathMode "searrow" 1; insertObject "\\searrow"}
  2556. proc swarrow {} {checkMathMode "swarrow" 1; insertObject "\\swarrow"}
  2557. proc nwarrow {} {checkMathMode "nwarrow" 1; insertObject "\\nwarrow"}
  2558.  
  2559. #--------------------------------------------------------------------------
  2560. # Dots:
  2561. #--------------------------------------------------------------------------
  2562.  
  2563. proc cdots {} {checkMathMode "cdots" 1; insertObject "\\cdots"}
  2564. proc vdots {} {checkMathMode "vdots" 1; insertObject "\\vdots"}
  2565. proc ddots {} {checkMathMode "ddots" 1; insertObject "\\ddots"}
  2566.  
  2567. #--------------------------------------------------------------------------
  2568. # Symbols:
  2569. #--------------------------------------------------------------------------
  2570.  
  2571. proc aleph {} {checkMathMode "aleph" 1; insertObject "\\aleph"}
  2572. proc hbar {} {checkMathMode "hbar" 1; insertObject "\\hbar"}
  2573. proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
  2574. proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
  2575. proc ell {} {checkMathMode "ell" 1; insertObject "\\ell"}
  2576. proc wp {} {checkMathMode "wp" 1; insertObject "\\wp"}
  2577. proc Re {} {checkMathMode "Re" 1; insertObject "\\Re"}
  2578. proc Im {} {checkMathMode "Im" 1; insertObject "\\Im"}
  2579. proc mho {} {
  2580.     if {[isSymbolPackageLoaded]} then {
  2581.         checkMathMode "mho" 1; insertObject "\\mho"
  2582.     }
  2583. }
  2584. proc prime {} {checkMathMode "prime" 1; insertObject "\\prime"}
  2585. proc emptyset {} {checkMathMode "emptyset" 1; insertObject "\\emptyset"}
  2586. proc nabla {} {checkMathMode "nabla" 1; insertObject "\\nabla"}
  2587. proc surd {} {checkMathMode "surd" 1; insertObject "\\surd"}
  2588. proc top {} {checkMathMode "top" 1; insertObject "\\top"}
  2589. proc bot {} {checkMathMode "bot" 1; insertObject "\\bot"}
  2590. # proc | {} {checkMathMode "|" 1; insertObject "\\|"}
  2591. proc angle {} {checkMathMode "angle" 1; insertObject "\\angle"}
  2592. proc forall {} {checkMathMode "forall" 1; insertObject "\\forall"}
  2593. proc exists {} {checkMathMode "exists" 1; insertObject "\\exists"}
  2594. proc neg {} {checkMathMode "neg" 1; insertObject "\\neg"}
  2595. proc flat {} {checkMathMode "flat" 1; insertObject "\\flat"}
  2596. proc natural {} {checkMathMode "natural" 1; insertObject "\\natural"}
  2597. proc sharp {} {checkMathMode "sharp" 1; insertObject "\\sharp"}
  2598. proc backslash {} {checkMathMode "backslash" 1; insertObject "\\backslash"}
  2599. proc partial {} {checkMathMode "partial" 1; insertObject "\\partial"}
  2600. proc infty {} {checkMathMode "infty" 1; insertObject "\\infty"}
  2601. proc Box {} {
  2602.     if {[isSymbolPackageLoaded]} then {
  2603.         checkMathMode "Box" 1; insertObject "\\Box"
  2604.     }
  2605. }
  2606. proc Diamond {} {
  2607.     if {[isSymbolPackageLoaded]} then {
  2608.         checkMathMode "Diamond" 1; insertObject "\\Diamond"
  2609.     }
  2610. }
  2611. proc triangle {} {checkMathMode "triangle" 1; insertObject "\\triangle"}
  2612. proc clubsuit {} {checkMathMode "clubsuit" 1; insertObject "\\clubsuit"}
  2613. proc diamondsuit {} {checkMathMode "diamondsuit" 1; insertObject "\\diamondsuit"}
  2614. proc heartsuit {} {checkMathMode "heartsuit" 1; insertObject "\\heartsuit"}
  2615. proc spadesuit {} {checkMathMode "spadesuit" 1; insertObject "\\spadesuit"}
  2616.  
  2617. #--------------------------------------------------------------------------
  2618. # Functions:
  2619. #--------------------------------------------------------------------------
  2620.  
  2621. proc arccos {} {checkMathMode "arccos" 1; insertObject "\\arccos"}
  2622. proc arcsin {} {checkMathMode "arcsin" 1; insertObject "\\arcsin"}
  2623. proc arctan {} {checkMathMode "arctan" 1; insertObject "\\arctan"}
  2624. proc arg {} {checkMathMode "arg" 1; insertObject "\\arg"}
  2625. proc cos {} {checkMathMode "cos" 1; insertObject "\\cos"}
  2626. proc cosh {} {checkMathMode "cosh" 1; insertObject "\\cosh"}
  2627. proc cot {} {checkMathMode "cot" 1; insertObject "\\cot"}
  2628. proc coth {} {checkMathMode "coth" 1; insertObject "\\coth"}
  2629. proc csc {} {checkMathMode "csc" 1; insertObject "\\csc"}
  2630. proc deg {} {checkMathMode "deg" 1; insertObject "\\deg"}
  2631. proc det {} {checkMathMode "det" 1; insertObject "\\det"}
  2632. proc dim {} {checkMathMode "dim" 1; insertObject "\\dim"}
  2633. proc exp {} {checkMathMode "exp" 1; insertObject "\\exp"}
  2634. proc gcd {} {checkMathMode "gcd" 1; insertObject "\\gcd"}
  2635. proc hom {} {checkMathMode "hom" 1; insertObject "\\hom"}
  2636. proc inf {} {checkMathMode "inf" 1; insertObject "\\inf"}
  2637. proc ker {} {checkMathMode "ker" 1; insertObject "\\ker"}
  2638. proc lg {} {checkMathMode "lg" 1; insertObject "\\lg"}
  2639. proc lim {} {checkMathMode "lim" 1; insertObject "\\lim"}
  2640. proc liminf {} {checkMathMode "liminf" 1; insertObject "\\liminf"}
  2641. proc limsup {} {checkMathMode "limsup" 1; insertObject "\\limsup"}
  2642. proc ln {} {checkMathMode "ln" 1; insertObject "\\ln"}
  2643. proc log {} {checkMathMode "log" 1; insertObject "\\log"}
  2644. proc max {} {checkMathMode "max" 1; insertObject "\\max"}
  2645. proc min {} {checkMathMode "min" 1; insertObject "\\min"}
  2646. proc Pr {} {checkMathMode "Pr" 1; insertObject "\\Pr"}
  2647. proc sec {} {checkMathMode "sec" 1; insertObject "\\sec"}
  2648. proc sin {} {checkMathMode "sin" 1; insertObject "\\sin"}
  2649. proc sinh {} {checkMathMode "sinh" 1; insertObject "\\sinh"}
  2650. proc sup {} {checkMathMode "sup" 1; insertObject "\\sup"}
  2651. proc tan {} {checkMathMode "tan" 1; insertObject "\\tan"}
  2652. proc tanh {} {checkMathMode "tanh" 1; insertObject "\\tanh"}
  2653.  
  2654. proc bmod {} {checkMathMode "bmod" 1; insertObject "\\bmod"}
  2655. proc pmod {} {
  2656.     checkMathMode "pmod" 1
  2657.     if {[wrapObject "\\pmod{" "}Ñ"]} then {
  2658.         message "parenthesized mod set"
  2659.     } else {
  2660.         message "enter formula"
  2661.     }
  2662. }
  2663.  
  2664. #--------------------------------------------------------------------------
  2665. # Large Ops:
  2666. #--------------------------------------------------------------------------
  2667.  
  2668. proc insertLargeOp {commandName} {
  2669.     checkMathMode "$commandName" 1
  2670.     set currentPos [getPos]
  2671.     insertObject "\\$commandName\_{Ñ}^{Ñ}Ñ"
  2672.     goto $currentPos
  2673.     nextTabStop
  2674. }
  2675. proc sum {} {insertLargeOp "sum"}
  2676. proc prod {} {insertLargeOp "prod"}
  2677. proc coprod {} {insertLargeOp "coprod"}
  2678. proc int {} {insertLargeOp "int"}
  2679. proc oint {} {insertLargeOp "oint"}
  2680. proc bigcap {} {insertLargeOp "bigcap"}
  2681. proc bigcup {} {insertLargeOp "bigcup"}
  2682. proc bigsqcup {} {insertLargeOp "bigsqcup"}
  2683. proc bigvee {} {insertLargeOp "bigvee"}
  2684. proc bigwedge {} {insertLargeOp "bigwedge"}
  2685. proc bigodot {} {insertLargeOp "bigodot"}
  2686. proc bigotimes {} {insertLargeOp "bigotimes"}
  2687. proc bigoplus {} {insertLargeOp "bigoplus"}
  2688. proc biguplus {} {insertLargeOp "biguplus"}
  2689.  
  2690. #--------------------------------------------------------------------------
  2691. # Delimiters:
  2692. #--------------------------------------------------------------------------
  2693.  
  2694. proc delimitObject {leftDelim rightDelim} {
  2695.     if {[wrapObject $leftDelim $rightDelim]} then {
  2696.         message "formula delimited"
  2697.     } else {
  2698.         message "enter formula"
  2699.     }
  2700. }
  2701. proc parentheses {} { checkMathMode "parentheses" 1; delimitObject "(" ")Ñ" }
  2702. proc brackets {} { checkMathMode "brackets" 1; delimitObject "\[" "\]Ñ" }
  2703. proc braces {} { checkMathMode "braces" 1; delimitObject "\\\{" "\\\}Ñ" }
  2704. proc absoluteValue {} { checkMathMode "absoluteValue" 1; delimitObject "|" "|Ñ" }
  2705. proc getDelims {} {
  2706.     catch {prompt "Choose delimiters:" "parentheses" "" "parentheses" \
  2707.                   "brackets" "braces" "angle brackets" "vertical bars" \
  2708.                   "double bars" "ceiling" "floor"} delimType
  2709.     if {$delimType != "cancel"} then {
  2710.         case $delimType in {
  2711.             "parentheses" {
  2712.                 set leftDelim "("
  2713.                 set rightDelim ")"
  2714.             }
  2715.             "brackets" {
  2716.                 set leftDelim "\["
  2717.                 set rightDelim "\]"
  2718.             }
  2719.             "braces" {
  2720.                 set leftDelim "\\\{"
  2721.                 set rightDelim "\\\}"
  2722.             }
  2723.             "{vertical bars}" {
  2724.                 set leftDelim "|"
  2725.                 set rightDelim "|"
  2726.             }
  2727.             "{double bars}" {
  2728.                 set leftDelim "\\|"
  2729.                 set rightDelim "\\|"
  2730.             }
  2731.             "{angle brackets}" {
  2732.                 set leftDelim "\\langle"
  2733.                 set rightDelim "\\rangle"
  2734.             }
  2735.             "ceiling" {
  2736.                 set leftDelim "\\lceil"
  2737.                 set rightDelim "\\rceil"
  2738.             }
  2739.             "floor" {
  2740.                 set leftDelim "\\lfloor"
  2741.                 set rightDelim "\\rfloor"
  2742.             }
  2743.             default {
  2744.                 alertnote "\"$delimType\" not recognized"
  2745.                 return ""
  2746.             }
  2747.         }
  2748.         return [list $leftDelim $rightDelim]
  2749.     } else {return ""}
  2750. }
  2751. proc otherDelims {} {
  2752.     checkMathMode "otherDelims" 1
  2753.     set delims [getDelims]
  2754.     if {$delims != ""} then {
  2755.         set leftDelim [lindex $delims 0]
  2756.         set rightDelim [lindex $delims 1]
  2757.         delimitObject "$leftDelim" "$rightDelimÑ"
  2758.     }
  2759. }
  2760. proc {half-openInterval} {} {
  2761.     checkMathMode "half-openInterval" 1; delimitObject "(" "\]Ñ"
  2762. }
  2763. proc {half-closedInterval} {} {
  2764.     checkMathMode "half-closedInterval" 1; delimitObject "\[" ")Ñ"
  2765. }
  2766.  
  2767. proc insertBigDelims {leftDelim rightDelim isMultiline} {
  2768.     checkMathMode "insertBigDelims" 1
  2769.     if {$isMultiline} then {
  2770.         alertnote "Multi-line delimiters not yet implemented."
  2771.     } else {
  2772.         if {[wrapObject $leftDelim $rightDelim]} then {
  2773.             message "formula delimited"
  2774.         } else {
  2775.             message "enter formula"
  2776.         }
  2777.     }
  2778. }
  2779. proc bigParentheses {} {
  2780.     checkMathMode "bigParentheses" 1; insertBigDelims "\\left(" "\\right)Ñ" 0
  2781. }
  2782. proc bigBrackets {} {
  2783.     checkMathMode "bigBrackets" 1; insertBigDelims "\\left\[" "\\right\]Ñ" 0
  2784. }
  2785. proc bigBraces {} {
  2786.     checkMathMode "bigBraces" 1; insertBigDelims "\\left\\\{" "\\right\\\}Ñ" 0
  2787. }
  2788. proc bigAbsoluteValue {} {
  2789.     checkMathMode "bigAbsoluteValue" 1; insertBigDelims "\\left|" "\\right|Ñ" 0
  2790. }
  2791. proc otherBigDelims {} {
  2792.     checkMathMode "otherBigDelims" 1
  2793.     set delims [getDelims]
  2794.     if {$delims != ""} then {
  2795.         append leftDelim "\\left" [lindex $delims 0]
  2796.         append rightDelim "\\right" [lindex $delims 1]
  2797.         insertBigDelims "$leftDelim" "$rightDelimÑ" 0
  2798.     }
  2799. }
  2800. proc bigLeftBrace {} { checkMathMode "bigLeftBrace" 1; insertBigDelims "\\left\\\{" "\\right.Ñ" 0 }
  2801. proc otherMixedBigDelims {} {
  2802.     checkMathMode "otherMixedBigDelims" 1
  2803.     catch {prompt "Choose LEFT delimiter:" "parenthesis" "" "parenthesis" \
  2804.                   "bracket" "brace" "vertical bar" "double bar" \
  2805.                   "angle bracket" "ceiling" "floor" "slash" "backslash" \
  2806.                   "none"} delimType
  2807.     if {$delimType != "cancel"} then {
  2808.         case $delimType in {
  2809.             "parenthesis" {set leftDelim "("}
  2810.             "bracket" {set leftDelim "\["}
  2811.             "brace" {set leftDelim "\\\{"}
  2812.             "{vertical bar}" {set leftDelim "|"}
  2813.             "{double bar}" {set leftDelim "\\|"}
  2814.             "{angle bracket}" {set leftDelim "\\langle"}
  2815.             "ceiling" {set leftDelim "\\lceil"}
  2816.             "floor" {set leftDelim "\\lfloor"}
  2817.             "slash" {set leftDelim "/"}
  2818.             "backslash" {set leftDelim "\\backslash"}
  2819.             "none" {set leftDelim "."}
  2820.             default {
  2821.                 alertnote "\"$delimType\" not recognized"
  2822.                 return
  2823.             }
  2824.         }
  2825.         catch {prompt "Choose RIGHT delimiter:" "parenthesis" "" "parenthesis" \
  2826.                       "bracket" "brace" "vertical bar" "double bar" \
  2827.                       "angle bracket" "ceiling" "floor" "slash" "backslash" \
  2828.                       "none"} delimType
  2829.         if {$delimType != "cancel"} then {
  2830.             case $delimType in {
  2831.                 "parenthesis" {set rightDelim ")"}
  2832.                 "bracket" {set rightDelim "\]"}
  2833.                 "brace" {set rightDelim "\\\}"}
  2834.                 "{vertical bar}" {set rightDelim "|"}
  2835.                 "{double bar}" {set rightDelim "\\|"}
  2836.                 "{angle bracket}" {set rightDelim "\\rangle"}
  2837.                 "ceiling" {set rightDelim "\\rceil"}
  2838.                 "floor" {set rightDelim "\\rfloor"}
  2839.                 "slash" {set rightDelim "/"}
  2840.                 "backslash" {set rightDelim "\\backslash"}
  2841.                 "none" {set rightDelim "."}
  2842.                 default {
  2843.                     alertnote "\"$delimType\" not recognized"
  2844.                     return
  2845.                 }
  2846.             }
  2847.             insertBigDelims "\\left$leftDelim" "\\right$rightDelimÑ" 0
  2848.         }
  2849.     }
  2850. }
  2851.  
  2852. #--------------------------------------------------------------------------
  2853. # Accents:
  2854. #--------------------------------------------------------------------------
  2855.  
  2856. proc acute {} {
  2857.     checkMathMode "acute" 1
  2858.     if {[isSelection] > 1} then {
  2859.         alertnote "Warning: only a single character may be accented!"
  2860.     }
  2861.     if {[wrapObject "\\acute{" "}Ñ"]} then {
  2862.         message "accent set"
  2863.     } else {
  2864.         message "enter one character"
  2865.     }
  2866. }
  2867. proc bar {} {
  2868.     checkMathMode "bar" 1
  2869.     if {[isSelection] > 1} then {
  2870.         alertnote "Warning: only a single character may be accented!"
  2871.     }
  2872.     if {[wrapObject "\\bar{" "}Ñ"]} then {
  2873.         message "accent set"
  2874.     } else {
  2875.         message "enter one character"
  2876.     }
  2877. }
  2878. proc breve {} {
  2879.     checkMathMode "breve" 1
  2880.     if {[isSelection] > 1} then {
  2881.         alertnote "Warning: only a single character may be accented!"
  2882.     }
  2883.     if {[wrapObject "\\breve{" "}Ñ"]} then {
  2884.         message "accent set"
  2885.     } else {
  2886.         message "enter one character"
  2887.     }
  2888. }
  2889. proc check {} {
  2890.     checkMathMode "check" 1
  2891.     if {[isSelection] > 1} then {
  2892.         alertnote "Warning: only a single character may be accented!"
  2893.     }
  2894.     if {[wrapObject "\\check{" "}Ñ"]} then {
  2895.         message "accent set"
  2896.     } else {
  2897.         message "enter one character"
  2898.     }
  2899. }
  2900. proc dot {} {
  2901.     checkMathMode "dot" 1
  2902.     if {[isSelection] > 1} then {
  2903.         alertnote "Warning: only a single character may be accented!"
  2904.     }
  2905.     if {[wrapObject "\\dot{" "}Ñ"]} then {
  2906.         message "accent set"
  2907.     } else {
  2908.         message "enter one character"
  2909.     }
  2910. }
  2911. proc ddot {} {
  2912.     checkMathMode "ddot" 1
  2913.     if {[isSelection] > 1} then {
  2914.         alertnote "Warning: only a single character may be accented!"
  2915.     }
  2916.     if {[wrapObject "\\ddot{" "}Ñ"]} then {
  2917.         message "accent set"
  2918.     } else {
  2919.         message "enter one character"
  2920.     }
  2921. }
  2922. proc grave {} {
  2923.     checkMathMode "grave" 1
  2924.     if {[isSelection] > 1} then {
  2925.         alertnote "Warning: only a single character may be accented!"
  2926.     }
  2927.     if {[wrapObject "\\grave{" "}Ñ"]} then {
  2928.         message "accent set"
  2929.     } else {
  2930.         message "enter one character"
  2931.     }
  2932. }
  2933. proc hat {} {
  2934.     checkMathMode "hat" 1
  2935.     if {[isSelection] > 1} then {
  2936.         alertnote "Warning: only a single character may be accented!"
  2937.     }
  2938.     if {[wrapObject "\\hat{" "}Ñ"]} then {
  2939.         message "accent set"
  2940.     } else {
  2941.         message "enter one character"
  2942.     }
  2943. }
  2944. proc tilde {} {
  2945.     checkMathMode "tilde" 1
  2946.     if {[isSelection] > 1} then {
  2947.         alertnote "Warning: only a single character may be accented!"
  2948.     }
  2949.     if {[wrapObject "\\tilde{" "}Ñ"]} then {
  2950.         message "accent set"
  2951.     } else {
  2952.         message "enter one character"
  2953.     }
  2954. }
  2955. proc vec {} {
  2956.     checkMathMode "vec" 1
  2957.     if {[isSelection] > 1} then {
  2958.         alertnote "Warning: only a single character may be accented!"
  2959.     }
  2960.     if {[wrapObject "\\vec{" "}Ñ"]} then {
  2961.         message "accent set"
  2962.     } else {
  2963.         message "enter one character"
  2964.     }
  2965. }
  2966.  
  2967. proc widehat {} {
  2968.     checkMathMode "widehat" 1
  2969.     if {[isSelection] > 3} then {
  2970.         alertnote "Warning: only a few characters may be accented!"
  2971.     }
  2972.     if {[wrapObject "\\widehat{" "}Ñ"]} then {
  2973.         message "accent set"
  2974.     } else {
  2975.         message "enter a few characters"
  2976.     }
  2977. }
  2978. proc widetilde {} {
  2979.     checkMathMode "widetilde" 1
  2980.     if {[isSelection] > 3} then {
  2981.         alertnote "Warning: only a few characters may be accented!"
  2982.     }
  2983.     if {[wrapObject "\\widetilde{" "}Ñ"]} then {
  2984.         message "accent set"
  2985.     } else {
  2986.         message "enter a few characters"
  2987.     }
  2988. }
  2989.  
  2990. proc imath {} {checkMathMode "imath" 1; insertObject "\\imath"}
  2991. proc jmath {} {checkMathMode "jmath" 1; insertObject "\\jmath"}
  2992.  
  2993. #--------------------------------------------------------------------------
  2994. # Grouping:
  2995. #--------------------------------------------------------------------------
  2996.  
  2997. proc underline {} {
  2998.     checkMathMode "underline" 1
  2999.     if {[wrapObject "\\underline{" "}Ñ"]} then {
  3000.         message "selection underlined"
  3001.     } else {
  3002.         message "enter text"
  3003.     }
  3004. }
  3005. proc overline {} {
  3006.     checkMathMode "overline" 1
  3007.     if {[wrapObject "\\overline{" "}Ñ"]} then {
  3008.         message "selection overlined"
  3009.     } else {
  3010.         message "enter text"
  3011.     }
  3012. }
  3013. proc underbrace {} {
  3014.     checkMathMode "underbrace" 1
  3015.     if {[wrapObject "\\underbrace{" "}Ñ"]} then {
  3016.         message "selection underbraced"
  3017.     } else {
  3018.         message "enter text"
  3019.     }
  3020. }
  3021. proc overbrace {} {
  3022.     checkMathMode "overbrace" 1
  3023.     if {[wrapObject "\\overbrace{" "}Ñ"]} then {
  3024.         message "selection overbraced"
  3025.     } else {
  3026.         message "enter text"
  3027.     }
  3028. }
  3029. proc stackrel {} {
  3030.     checkMathMode "stackrel" 1
  3031.     set currentPos [getPos]
  3032.     if {[insertObject "\\stackrel{Ñ}{Ñ}Ñ"]} then {
  3033.         goto $currentPos
  3034.         nextTabStop
  3035.         message "1st arg scriptstyle"
  3036.     }
  3037. }
  3038.  
  3039. #--------------------------------------------------------------------------
  3040. # Spacing:
  3041. #--------------------------------------------------------------------------
  3042.  
  3043. proc negThin {} {checkMathMode "negThin" 1; insertObject "\\!"}
  3044. proc thin {} {checkMathMode "thin" 1; insertObject "\\,"}
  3045. proc medium {} {checkMathMode "medium" 1; insertObject "\\:"}
  3046. proc thick {} {checkMathMode "thick" 1; insertObject "\\;"}
  3047. proc quad {} {checkMathMode "quad" 1; insertObject "\\quad"}
  3048. proc qquad {} {checkMathMode "qquad" 1; insertObject "\\qquad"}
  3049. proc hspace {} {
  3050.     checkMathMode "hspace" 1
  3051.     if {[wrapObject "\\hspace{" "}Ñ"]} then {
  3052.         message "spacing set"
  3053.     } else {
  3054.         message "enter the desired horizontal spacing"
  3055.     }
  3056. }
  3057. proc vspace {} {
  3058.     checkMathMode "vspace" 1
  3059.     if {[wrapObject "\\vspace{" "}Ñ"]} then {
  3060.         message "spacing set"
  3061.     } else {
  3062.         message "enter the desired horizontal spacing"
  3063.     }
  3064. }
  3065. proc hfill {} {checkMathMode "hfill" 1; insertObject "\\hfill"}
  3066. proc vfill {} {checkMathMode "vfill" 1; insertObject "\\vfill"}
  3067. proc smallskip {} {checkMathMode "smallskip" 1; insertObject "\\smallskip"}
  3068. proc medskip {} {checkMathMode "medskip" 1; insertObject "\\medskip"}
  3069. proc bigskip {} {checkMathMode "bigskip" 1; insertObject "\\bigskip"}
  3070.  
  3071.